2

I have seen multiple forums but I'm not clear on the solution.

  1. When I try to invalidate the session in browser close event, my session is lost even on page refresh. I don't want my session to end on page refresh, I want my session to end on browser/tab close.

  2. Can I invalidate my session on browser close event using angularJs ?

Appreciate your help !

1 Answers1

0

Try out the HTML5 session storage. Data stored there will persist through refreshes but will be removed on page/tab closing. This should also work fine with Angular.

https://developer.mozilla.org/de/docs/Web/API/Window/sessionStorage

// Set something
sessionStorage.set('usertoken', '123456789');
// Get something
sessionStorage.get('usertoken');
  • Eskil, this is for a single value. but how can I use this to end the session on browser close? – user7242459 Dec 20 '16 at 16:14
  • How are you handling your sessions? If it's token-based then the above should work. Otherwise it'll be hard. My suggestion is to either move to token-based auth or set a timeout for the session. – Eskil Fogelström Dec 20 '16 at 22:59