Need to clear local storage on browser tab closed not on refresh
15,499
Refreshing and closing a tab/window is the same event as far as the browsers are concerned.
Best would be to use session storage
rather than local storage
as session would be active until the tab/window is closed and not refreshed and you aren't saving persistent data.
Have a look here
Related videos on Youtube
Comments
-
Sankar almost 2 years
Need to clear local storage on browser tab closed not on refresh. I tried
window.onbeforeunload = function (e) { localStorage.clear(); };
it clears the localstorage when browser refresh happens. I want to force the user to login when the user close browser tab.
-
Karan Dhir over 6 yearsPossible duplicate of stackoverflow.com/questions/9943220/…
-
Ramesh Rajendran over 6 yearsTry this
localStorage.$reset();
-
Ramesh Rajendran over 6 yearsPossible duplicate of How to delete a localStorage item when the browser window/tab is closed?
-