如何确定子窗口是否已在javascript中关闭

如何确定子窗口是否已在javascript中关闭

本文介绍了如何确定子窗口是否已在javascript中关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此页面,这会打开一个弹出窗口.我想在弹出窗口关闭后刷新父级..我使用了在stackoverflow中找到的功能

i have this page which opens up a popup. i want to refresh the parent after popup has been closed.. i used the function i found in stackoverflow

  var win = window.open("popup.html");

function doStuffOnUnload() {
     alert("Unloaded!");
  }

if (typeof win.attachEvent != "undefined") {
    win.attachEvent("onunload", doStuffOnUnload);
}
else if (typeof win.addEventListener != "undefined") {
    win.addEventListener("unload", doStuffOnUnload, false);
}

在我关闭弹出窗口后,什么也没做...我该怎么做?谢谢...

which didn't do anything after i closed the pop up... what can i do achieve this?thanks...

推荐答案

您在错误的位置写入了卸载事件.您将卸载事件添加到主页而不是弹出窗口中.

You wrote the unload event in the wrong place. You added an unload event to the main page instead of to the popup...

 var win = window.open("popup.html"); // O.K.

所有这些都应该在popup.html页面中...

All of this should be in the popup.html page...

function doStuffOnUnload() {
     alert("Unloaded!");
  }

 if (typeof win.attachEvent != "undefined") {
   win.attachEvent("onunload", doStuffOnUnload);
 } else if (typeof win.addEventListener != "undefined") {
  win.addEventListener("unload", doStuffOnUnload, false);
  }

您可以使用unload jquery函数:

You can use the unload jquery function:

$(window).unload(doStuffOnUnload);

unload 文档

这篇关于如何确定子窗口是否已在javascript中关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:34