Click here to Skip to main content
15,072,046 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We have the situation that on Tab / browser close user will logout from the application. We are able to logout user on browser / Tab close, but on browser reload button click user also get logged out of the system.

How we can avoid the user logged out from the browser reload button click?

What I have tried:

We have tried with onbeforeunload event but its not working as we expected.
Updated 2-Apr-19 0:54am

You don't get any specific events for closing tabs or the browser so it's not possible to know when those things are happening, how the browser works is not a part of the html specification. I don't even know what a "browser reload" button is, it is obviously a function of a specific browser you are using, how do you expect something specific to one browser to be supported by a global standard?

Stop trying to log people out when they close things. Use non-persistent cookies for your authentication and when they close the browser their auth session also dies and they need to log in again. If you're trying to stop people logging in multiple times then stop doing that also, it's not possible with a stateless technology like the web.
I did a quick search on Google with the title of your question: How to detect browser close and reload button click event in javascript - Google Search[^] and found the following: javascript - Trying to detect browser close event - Stack Overflow[^] and javascript - Trying to detect browser close event - Stack Overflow[^] and others ... pick one that suits you best.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900