简体   繁体   中英

How to capture browser window clsoing event?

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.

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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM