detect refresh browser for unload/beforeunload when browser closed

前端 未结 1 986
小鲜肉
小鲜肉 2020-12-20 02:27

This is actually continuation of my last question. I still face problem since when i refresh browser, either unload or beforeunload also fired which I only want them when br

相关标签:
1条回答
  • 2020-12-20 03:28

    As far as I know it is impossible to detect a browser close separately from a browser refresh, because the browser does not provide the webpage (window) with that information. As far as your page and its Javascript code are concerned, the two are one and the same.

    Since it's browser info that you need, the only way to get it is to use something that has access to that info, ie. a browser plug-in. But then you'll need to make a plug-in for each browser, and get every user to install it. Since I highly doubt you'll find this worthwhile, the real answer to your question (as frustrating as it may be) is: stop trying to detect refreshes vs. closes and move on.

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