In Angular 2 application we store the token in local storage, now i want to clear the token on browser closing when user not check the remember me option during login. i did it through unload browser event but problem with that event is not fire when user close the browser from task manager in window.
The following should accomplish this...
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();
}
}
Note : onBeforeUnload is executing on browser close event
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With