I have library which wrapped with an IIFE and placed to .js file,and it looks and works generally in this way:
(function (libraryObject) {
libraryObject.doSomething = function (){
document.getElementById() ....
}
})((window.library = window.library || {}));
When I import it to my React app I just do:
import './library'
So it injects to window in which my React app initialized.
And document object also belongs to this window and when I call for ex:
window.library.doSomething()
It will work with context of this document, so document.getElementById() .... inside library will work with the same document.
But I need open an child popup with const myChildPopup = window.open() and inject this library in context of my child popup and next library can do something in document of my child popup, something like this:
myChildPopup.libraryObject.doSomething().
So that the document object in this case inside library will reffer myChildPopup.document. For ex:
document.getElementById() .... // document === myChildPopup.document
Any ideas how to do this?