开发者

detect when a window I've opened closes - js

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,scro开发者_如何学运维llbars=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!


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';
};


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

You can also use addEventListener.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜