Is there a way to determine that the browser window was closed?

前端 未结 8 383
感动是毒
感动是毒 2021-01-14 12:35

How is it possible to identify that the browser\'s close button was clicked?

8条回答
  •  北海茫月
    2021-01-14 13:22

    You should use onbeforeunload, not onunload. IE 7 (and perhaps other browsers) are not 100% reliable when it comes to firing the unload event, but it seems to always fire the beforeunload event.

    for example:

    window.onbeforeunload=function(){}
    

    or, if you are using prototype.js:

    Event.observe(window, 'beforeunload', function(){});
    

提交回复
热议问题