javascript中如何判断子窗口是否已关闭?
我有这个页面,它会打开一个弹出窗口。我想在弹出窗口关闭后刷新父级。我使用了在 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);
}
该函数在我关闭弹出窗口后没有执行任何操作...我可以做什么来实现此目的? 谢谢...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将卸载事件写在错误的位置。您将卸载事件添加到主页而不是弹出窗口...
所有这些都应该在 popup.html 页面中...
您可以使用
unload
jquery 函数:unload
文档You wrote the unload event in the wrong place. You added an unload event to the main page instead of to the popup...
All of this should be in the popup.html page...
You can use the
unload
jquery function:unload
docs