How would I raise an event (jQuery or vanilla Javascript) when a popup window is closed?

后端 未结 8 1045
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 18:06

I want to raise an event when a popup window is closed, or preferably, just before closing. I\'m storing the popup window object as an object, but I don\'t know of any way to bi

8条回答
  •  半阙折子戏
    2021-02-13 18:56

    I tried the watcher approach but ran in to the "permission denied" issue while using this in IE6. This happens due to the closed property not being fully accessible around the event of closing the window ... but fortunately with a try { } catch construction it works though :o)

    var w = window.open("http://www.google.com", "_blank", 'top=442,width=480,height=460,resizable=yes', true);
    
    var watchClose = setInterval(function() {
        try {
            if (w.closed) {
                clearTimeout(watchClose);
                //Do something here...
            }
        } catch (e) {}
    }, 200);
    

    Thank you magnus

提交回复
热议问题