Delete a localStorage item when the browser window/tab is closed
We can use the window.beforeunload event to find out if a tab is closed and then we can clear the local storage. beforeunload
event gets triggered when a window or browser tab is about to close.
Advertisements
window.onbeforeunload = () => { localStorage.removeItem('isLoggedin'); }