Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

javascript - detect refresh browser for unload/beforeunload when browser closed

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...