0

我在这里面临一个无聊的问题。我需要在子窗口的关闭事件中调用父窗口上的函数。我的代码是这样的:

$(function(){
    $("#btnPlay").click(function(){
        ShowPopup("URL", 600, 600, DoSomeStuff);

    });
});
function DoSomeStuff(){
    // Do some stuff
}
function ShowPopup(url, width, height, closeCallback){
    var options = "resizable=yes, status=no, location=no, menubar=no, width= " + width + ",height=" + height;
    var w = window.open(url, "_blank", options );
    w.onunload = function(){ 
        // INVOKE DoSomeStuff of the parent window
        console.log("X");
    }

}

但似乎onunload事件没有被调用!可能有什么问题?

4

1 回答 1

0

我认为你非常接近。

尝试:

function ShowPopup(url, width, height, closeCallback){
    var options = "resizable=yes, status=no, location=no, menubar=no, width= " + width + ",height=" + height;
    var w = window.open(url, "_blank", options );
    w.onunload = function(){ 
        closeCallback();
        console.log("X");
    }
}
于 2012-11-09T00:14:38.173 回答