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

后端 未结 8 854
没有蜡笔的小新
没有蜡笔的小新 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:58

    From what I checked the jQuery unload is just a wrapper for the native function. I could be wrong as I didn't dug that deep.

    This example worked for me.

    $(document).ready(function(){
        $(window).unload( function (){
            alert('preget');
            $.get(
                '/some.php',
                { request: 'some' }
            );
            alert('postget');
        });
    });
    

    Remember that some browsers block the window.open requests on unload, IE for example.

提交回复
热议问题