Trying to detect browser close event

后端 未结 11 743
广开言路
广开言路 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:39

    Try following code works for me under Linux chrome environment. Before running make sure jquery is attached to the document.

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

    For simple follow following steps:

    1. open http://jsfiddle.net/
    2. enter something into html, css or javascript box
    3. try to close tab in chrome

    It should show following picture:

    enter image description here

提交回复
热议问题