Can the parent window be notified when a child window closes? (on a different domain?)
Trying to get around the window.opener not working when on different domains.
Can I at least be notified somehow when the child window closes?
If you store a reference to the child window when you call window. open() , then you can poll using setInterval() to see whether the window is still open using the window. closed property.
open("http://www.google.com"); function checkWindow() { if (childWindow && childWindow. closed) { window. clearInterval(intervalID); alert('closed'); } } var intervalID = window. setInterval(checkWindow, 500);
To obtain a window's owner window, instead of using GetParent, use GetWindow with the GW_OWNER flag. To obtain the parent window and not the owner, instead of using GetParent, use GetAncestor with the GA_PARENT flag.
You can't directly be notified of the window closing, but you can work out when the child window has been closed by inspecting the closed
property on the window object reference returned by window.open()
.
Here's an example that will display an alert within 5 seconds of the child window being closed by polling the closed
property:
var win = open('http://www.google.com');
var intervalId = setInterval(function() {
if (win.closed) {
clearInterval(intervalId);
alert('Window closed! Hoorah!');
}
}, 5000);
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