We've got the following situation, running from a single domain:
Page A uses window.open()
to open a named window (a popup player). window.open()
gives page A a reference to the window.
User now reloads page A. The reference to the named window is lost. Using window.open()
to "find" the window has the unfortunate side effect of reloading it (undesirable). Is there any other way to get a reference to this window?
When window. open() returns, the window always contains about:blank . The actual fetching of the URL is deferred and starts after the current script block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.
How to check if an opened browser window is closed or not in JavaScript? To check if an opened browser window is closed, you can use the closed property in referenced window object in JavaScript. The property returns a boolean true if the window is closed and false if the window is in the opened state.
Typically the onclick event on the "Yes" or "Ok" button in the modal dialog looks like this: window. returnValue = true; window. close();
Try this:
var playerUrl = 'http://my.player...'; var popupPlayer= window.open('', 'popupPlayer', 'width=150,height=100') ; if(popupPlayer.location.href == 'about:blank' ){ popupPlayer.location = playerUrl ; } popupPlayer.focus();
It will open a blank window with a unique name. Since the url is blank, the content of the window will not be reloaded.
AFAIK, no there isn't..
A kind-of-dirty-but-i-guess-it-will-work hack would be to periodically reset the reference on the parent window from within the popup using window.opener, with something like this code:
setInterval(function() { if(window.opener) { window.opener.document.myPopupWindow = window } }, 100)
In the parent window, you'll be able to access document.myPopupWindow, even after a reload (well, 100ms after the reload). This should work cross browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With