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

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

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

相关标签:
8条回答
  • 2021-01-14 13:38

    There is usually an event which fires when the user leaves the page (unload?) - this may be browser specific.

    There is also a property, window.closed, which is set on the window object after its associated window is closed. This is typically used when you have a reference to a popup window.

    I'm not sure whether the unload event would be fired before or after the "closed" property is set - you'll have to experiment.

    It may be that you can't distinguish between a closed window and a browser which has gone to another site.

    0 讨论(0)
  • 2021-01-14 13:42

    Browsers do not have a close event so you can't really tell when the user has closed their browser, there are some potential workarounds in This thread

    If you let us know what you are trying to achieve, there may be an alternative way

    0 讨论(0)
提交回复
热议问题