Trying to detect browser close event

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

    Following script will give message on Chrome and IE:

    
    

    Chrome
    enter image description here

    IE
    enter image description here

    on Firefox you will get generic message

    enter image description here

    Mechanism is synchronous so no server calls to delay will work, you still can prepare a mechanism like modal window that is shown if user decides to stay on page, but no way to prevent him from leaving.

    Response to question in comment

    F5 will fire event again, so will Atl+F4.

提交回复
热议问题