0

Hi I want to capture event of windows closing and want to remove session values . After several search I found onBeforeUnload event which is triggered each time when you navigate to different page or unloads the page.even on reload this event will be triggered which is not my requirement. I want specific only windows closing event in all browsers to invalidate the session values.

Linga
  • 10,379
  • 10
  • 52
  • 104
mad_
  • 8,121
  • 2
  • 25
  • 40
  • There is no event triggered specifically for the window closing. The only thing I can think of that might help would be to have a small session timeout (10 seconds, for example) and an ajax call in an interval that keeps the session alive. Then when they leave your site the session is destroyed after 10 seconds. That said, if you explain *why* you want to do this then there will probably be a more suitable solution. – Reinstate Monica Cellio Nov 18 '15 at 08:15

1 Answers1

-1

Run JavaScript code on window close or page refresh?

/* The most acceptable answer seemed to be as follows in vanilla JS 
   and was addressed at the linked address already.*/    
window.onbeforeunload = closingCode;
function closingCode(){
   //I would capture the URL prior to unload here and if it does NOT
   //exist or is not your url domain then you can unload variables here 
   return false;

}
Mike Horstmann
  • 580
  • 2
  • 9