Rahul Gupta
Rahul Gupta

Reputation: 994

how to remove data from localStorage when browser is closed not when tab is closed?

I used window.onunload and tried window.onbeforeunload but both are clearing the data on tab close as well. I want the data to remain when tab is closed and it should clear it out when the entire browser is closed. Any solution on this?

Upvotes: 1

Views: 1440

Answers (2)

Frenk
Frenk

Reputation: 91

You should take a look at sessionStorage: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API#sessionStorage

Upvotes: 1

Matto
Matto

Reputation: 118

That's not possible. Unluckily there is no event fired when closing the entire browser (at least not in Chrome, Firefox and Internet Explorer).

You will have to find another solution to achieve what you need :(

Upvotes: 1

Related Questions