tags:

views:

39

answers:

2

Hi all,

I am building a small web app. In the app I open a window using JS:

signinWin = window.open("myWindow.htm", "SignIn", "width=600,height=270,location=0,toolbar=0,scrollbars=0,status=0,status=false,statusbar=false,titlebar=no,dependent,alwaysraised,resizable=0,menuBar=0,left=" + 300 + ",top=" + 300);

I wish to be notified via event when the user closes the window.

How can this be done?

Thank you!

A: 
signinWin.onunload = function(){
  // do something
}

You can also use addEventListener.

Matthew Flaschen
A: 

Looks like the onBeforeUnload event is the closest thing to what you're looking for. However, it will fire with lots of page events inside that window. For example... closing the browser, refreshing, clicking a link, posting a form, etc.

signinWin.onbeforeunload = function (e) {
  var e = e || window.event;

  // For IE and Firefox
  if (e) {
    e.returnValue = 'Any string';
  }

  // For Safari
  return 'Any string';
};
jessegavin