根据文档(我只使用Firefox):
https://developer.mozilla.org/en/DOM/window.onunload
卸载文档时会引发 unload 事件。
但是即使子窗口(即变量名“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();