为什么弹出页面打开时会调用js onunload?
根据文档(我只使用Firefox):
https ://developer.mozilla.org/en/DOM/window.onunload
当 文档已卸载。
但是我下面的代码会触发警报,即使子窗口(即变量名称“win”)刚刚打开,而不是关闭。
alert("failed but still reload:" + win.isSuccess);
"failed but still reload: undefined"
我的注意力是在子窗口关闭时调用 onunload 。我在这里做错了什么?
代码
function showInsertPopup() {
var ddId = document.getElementById("workRegionDropdown");
var index = ddId.selectedIndex;
var workRegionCode = ddId.options[index].value;
if(workRegionCode != "") {
var win = window.open(machineFormPopup + "?typeFlag=1&workRegionCode=" + workRegionCode, "window1", "menubar=no, width=700, height=550, toolbar=no");
win.onunload = function() {
if(win.isSuccess) {
alert("success reload!")
getRecordByWorkRegion();
}
else {
//here gets print out somehow
alert("failed but still reload:" + win.isSuccess);
getRecordByWorkRegion();
}
}//end inner function onunload
}
}//end showInsertPopup()
子窗口页面只有简单的js:
window.isSuccess = 1;
window.close();
According to the documentation (I'm only using Firefox) :
https://developer.mozilla.org/en/DOM/window.onunload
The unload event is raised when the
document is unloaded.
But my code below would trigger the alert even though the child window (i.e. variable name "win") has just been opened, not closed.
alert("failed but still reload:" + win.isSuccess);
"failed but still reload: undefined"
My attention is to invoke that onunload when the child window is closed. What am I doing wrong here??
Code
function showInsertPopup() {
var ddId = document.getElementById("workRegionDropdown");
var index = ddId.selectedIndex;
var workRegionCode = ddId.options[index].value;
if(workRegionCode != "") {
var win = window.open(machineFormPopup + "?typeFlag=1&workRegionCode=" + workRegionCode, "window1", "menubar=no, width=700, height=550, toolbar=no");
win.onunload = function() {
if(win.isSuccess) {
alert("success reload!")
getRecordByWorkRegion();
}
else {
//here gets print out somehow
alert("failed but still reload:" + win.isSuccess);
getRecordByWorkRegion();
}
}//end inner function onunload
}
}//end showInsertPopup()
Child window page has just simple js:
window.isSuccess = 1;
window.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您首先会在弹出窗口中看到原始
about:blank
文档的卸载。 (您可以通过查看窗口的位置来验证这一点。)然后,当弹出窗口关闭时,您应该会看到另一个卸载。You actually see the unload for the original
about:blank
document in the popup window first. (You can verify this by looking at the window's location.) You should then see another unload when the popup window closes.