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
1 Answer
Reset to default 3As 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.