3

根据文档(我只使用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();
4

1 回答 1

2

about:blank您实际上首先会在弹出窗口中看到原始文档的卸载。(您可以通过查看窗口的位置来验证这一点。)当弹出窗口关闭时,您应该会看到另一个卸载。

于 2011-01-20T20:52:53.993 回答