How reference popup object when opener page changes?
- by achairapart
This is driving me crazy!
Scenario:
The main page opens a pop-up window and later calls a function in it:
newWin = window.open(someurl,'newWin',options);
...some code later...
newWin.remoteFunction(options);
and it's ok.
Now, popup is still open and Main Page changes to Page 2. In Page 2 newWin doesn't exist anymore and I need to recreate the popup window object reference in order to call again the remote function (newWin.remoteFunction)
I tried something like:
newWin = open('','newWin', options);
if (!newWin || newWin.closed || !newWin.remoteFunction) {
newWin = window.open(someurl,'newWin',options);
}
And it works, I can call newWin.remoteFunction again BUT Safari for some reason gives Focus() to the popup window everytime the open() method is called breaking the navigation (I absolutely need the popup working in the background).
Only workaround I can think to solve this is to create an interval in the popup with:
if(window.opener && !window.opener.newWin) window.opener.newWin = self;
and then set another interval in the opener Page with some try/catch but it is inelegant and very inefficient.
so, I wonder, it's really so hard to get the popup object reference between different pages in the opener window?