0

I need to end a user session only in case when user closes the window. I want to retain session if the user refreshes the page or hard reload the page(chrome) with ctrl+shift+r.

I have read post on this forum about usage of window.unload method but this method is called also in case of user refreshes the page with F5 or hard reload it or keep his cursor in address bar and hit enter. I only want to end the user session in case he close a tab or window.

Thanks, Hitesh

Hitesh Bhutani
  • 333
  • 1
  • 7
  • 21
  • Bumped into this post. Looks like there is not pure way to determine this. http://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser – Hitesh Bhutani Aug 09 '15 at 03:21
  • I would say the client solution is not a reliable one. What if, for some reason, the user has 2 windows with different pages of the site open and then closes one of them. I would stick with the the server session expiration solution. – i-- Aug 09 '15 at 03:55
  • @i-- I agree. Infact server session i just mentioned for an example. Actually i want to do something else rather than expiring the session. Anyhow i will have to think of some alternate way. – Hitesh Bhutani Aug 09 '15 at 04:01

1 Answers1

0

You can not do it in pure HTML5. This is a security feature of modern navigators.

Emilio Platzer
  • 2,327
  • 21
  • 29