Smile

Smile

  • 1.2k
  • 198
  • 36.5k

Event to know when a browser is closed

Feb 3 2020 5:44 AM
I have a website with mutliple tabs and with multiple menu items with a master page.How to know when the browser/tab is closed.I need to close a thread on browser close.
 
I Haved tried this event
  1. <script type="text/javascript">  
  2. window.addEventListener('beforeunload'function (e) {  
  3. e.preventDefault();  
  4. e.returnValue = '';  
  5. });  
  6. </script>  
This event is getting invoked when i am moving from one tab to other and even from one menu item to other.I want to know only when the the browser/tab is getting closed.

Answers (3)