Trying to detect browser close event

后端 未结 11 728
广开言路
广开言路 2020-11-22 05:56

I have tried many methods to detect browser close event through jQuery or JavaScript. But, unfortunately, I have not been able to detect the close. The onbeforeunload<

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 06:20

    As Phoenix said, use jQuery .bind method, but for more browser compatibility you should return a String,

    $(document).ready(function()
    {
        $(window).bind("beforeunload", function() { 
            return "Do you really want to close?"; 
        });
    });
    

    more details can be found at : developer.mozilla.org

提交回复
热议问题