Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the parent window be notified when a child window closes? (on a diff domain)

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?

like image 250
Blankman Avatar asked Apr 23 '09 13:04

Blankman


People also ask

How do I listen to my child closing windows?

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.

How do you check parent window is closed or not?

open("http://www.google.com"); function checkWindow() { if (childWindow && childWindow. closed) { window. clearInterval(intervalID); alert('closed'); } } var intervalID = window. setInterval(checkWindow, 500);

Which method is used to get parent window?

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.


1 Answers

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);
like image 117
Simon Lieschke Avatar answered Oct 21 '22 20:10

Simon Lieschke