I have to cleared the local storage when browser is closed or the tab in which the site is open is closed but if the website is open in more than one tab than local storage will not be cleared until the last tab is closed.
I have used @HostListener('window:unload', [ '$event' ]) in angular 6. But the problem is that it cannot differentiate between tab closed or window closed. Please help me in finding the solution for this.
export class AppComponent {
@HostListener('window:unload', [ '$event' ])
unloadHandler(event) {
alert('call unload');
}
@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHander(event) {
alert('call beforeunload');
}
}
I want to differentiate between tab closed and browser closed.