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.
Asked
Active
Viewed 44 times
0
-
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 Answers
-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
-
OP specifically mentions this and says it's not what he wants. – Reinstate Monica Cellio Nov 18 '15 at 08:16
-
It is for prevention of navigation to other page which is again not my requirement. I want only event of closing the browser window . – mad_ Nov 18 '15 at 08:36