0

How to detect Tab close in web browser and Browser Reload in Angular?

My problem is , I need to remove a key in local storage when the browser tab is closed.

I used Host Listener with 'window:beforeunload' ,

@HostListener('window:beforeunload', ['$event'])
beforeunloadHandler(event) {
  // remove local storage key here
}

But , When tab is Reload it clear the key in local storage. In my problem session storage cannot be used.

  • 1
    Does this answer your question? [Identifying Between Refresh And Close Browser Actions](https://stackoverflow.com/questions/568977/identifying-between-refresh-and-close-browser-actions) – Harun Yilmaz Jan 09 '23 at 08:06
  • @HarunYilmaz duration is below 20 every time when it reload the page and close the tab. So how to detect it as a browser close or a browser reload? – Chiranjaya Denuwan Jan 09 '23 at 08:36

0 Answers0