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

后端 未结 8 897
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  Happy的楠姐
    2021-02-13 19:09

    The jQuery code example for the unload event

    $(window).unload( function () { alert("Bye now!"); } );

    From the jQuery unload documentation

    Edit:

    I played around and was not able to get the parent window to be able to set the unload. The only way I could get it to work, was by having the script present in the popup window html. The popup window also needed to load jQuery. I have nothing to base this on, but I believe the unload is being triggered, because essentially the popup window is being unloaded from the scope of the parent window. Just a guess.

提交回复
热议问题