title: Clear local storage when the browser closes in angular
body: <p>I have created an angular 5 application. Which is using a token based system.Currently I am storing the token in the localstorage.I want the localstorage to be clear when the browser closes. and not clear the localstorage when the browser refreshes.The reason that I didn't use sesionstorage is because opening a page in a new tab or window will cause a new session to be initiate. How can I done this I tried with this code in app.component </p>
  
  <pre><code>@HostListener('window:beforeunload', ['$event'])
    beforeunloadHandler(event) {
    alert("KKk")
    localStorage.removeItem('authToken');
  }
  </code></pre>
  
  <p>But it is not firing when the browser closes.What is the best method to achieve this use case. Whether using cookie storage is a good method in case of tokens</p>