javascript - detect refresh browser for unloadbeforeunload when browser closed - Stack Overflow

This is actually continuation of my last question. I still face problem since when i refresh browser, e

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 browser closed. Just crossed on my mind to use window.outerHeight or window.innerHeight but still can't figure out how to do this. Any suggestion/snippet? Thanks in advance.

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 browser closed. Just crossed on my mind to use window.outerHeight or window.innerHeight but still can't figure out how to do this. Any suggestion/snippet? Thanks in advance.

Share Improve this question edited May 23, 2017 at 11:51 CommunityBot 11 silver badge asked Dec 28, 2012 at 0:14 Doni Andri CahyonoDoni Andri Cahyono 7935 gold badges16 silver badges29 bronze badges 9
  • 3 As far as the server or browser is concerned, a close and a navigation away from the page are synonymous. – Brad Christie Commented Dec 28, 2012 at 0:18
  • @BradChristie: If it's synonymous then there'll be no chance to isolate unload/beforeunload event only for closing browser? – Doni Andri Cahyono Commented Dec 28, 2012 at 0:33
  • Correct assumption. You can catch a revisit because the server will have a new action to execute, but you can't catch the absense of that (closing the window) if nothing ever happened. that's why websites use "time elapsed since last visit" to determine who's "still online". – Brad Christie Commented Dec 28, 2012 at 0:36
  • @BradChristie: So, how can i distinguish between unload/beforeunload for refresh and closing browser? Or do you have a suggestion how to solve my case? – Doni Andri Cahyono Commented Dec 28, 2012 at 0:41
  • 1 @DoniAndriCahyono you can't distinguish between them. – DA. Commented Dec 28, 2012 at 0:49
 |  Show 4 more ments

1 Answer 1

Reset to default 3

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745225915a4617460.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信