We help IT Professionals succeed at work.

Notify when external window closes

Axter
Axter asked
on
I have a page that opens a form on a popup window.
            $('.mrlisting_tr').dblclick(function() {
                        window.open('mr_details.php?Mr=' + this.cells[0].firstChild.data + '&Testdb=<?php print $Testdb; ?>', 'MR_Edit', windowSize);
                  });

I like the page that open the window to get notify when the window is closed.  Is there any way to do that with jquery or javascript?
Comment
Watch Question

Commented:
Try this out

// In the window that opens the new window

var win = window.open( ... );
win.onunload = function() {
  if (window.opener && typeof(window.opener.onPopupClosed) == 'function') {
    window.opener.onPopupClosed();
  }
};

window.onPopupClosed = function() {
  alert("You closed the pop up!");
};

Open in new window

Commented:
Do as follows!

In parent window page add javascript function:

 
function alert_child_closed() {
alert("child window just closed");
}

Open in new window


In child (popup) window add javascript function:

 
window.onbeforeunload = function() {
   alertParent();
}

 function alertParent() {
   window.opener.alert_child();
}

Open in new window

Author

Commented:
Sorry for late responds.
experts1, I was able to get your solution to work.  I just had to rename alert_child_closed function in the child to alert_child_closed, as in parrent.

Thanks