I would like to know when the
- browser window is closed and not the tab
- and if possible, when the last tab with my app is closed
Following is the only thing i have found:
Clear local storage when the browser closes in angular
I have tried the mentioned code with both onBeforeUnload
and beforeunload
, it is not firing for me.
Here is the code:
import { Component, HostListener } from "@angular/core";
@Component({
selector: 'app-root',
templateUrl:"./app/app.component.html"
})
export class AppComponent {
@HostListener("window:onbeforeunload",["$event"])
clearLocalStorage(event){
localStorage.clear();
}
}
I am interested in clearing one item placed in storage at the very end.
Or should i use cookie, but will it go away after the last tab / browser has been closed? Here is the cookie example