I want to remove a particular item in the local storage after I quit the whole browser(not just the tab). I have searched google and I only got the answer for removing when (tab) closes and not whole application (the browser), any suggestions?
Asked
Active
Viewed 48 times
0
-
In this case why not use session storage then. session storage is destroyed when someone leaves the session – Rob Terrell Feb 09 '21 at 21:26
-
can I do it in react? – Dasto Feb 09 '21 at 21:27
-
1yeah you can do it in any javascript framework – Rob Terrell Feb 09 '21 at 21:28
-
literally operates in an identical way to local storage – Rob Terrell Feb 09 '21 at 21:28
-
so it automatically deletes it after browser closes or I have to pass in a particular option? – Dasto Feb 09 '21 at 21:29
-
automatically deletes it – Rob Terrell Feb 09 '21 at 21:29
-
thats the essence of session storage. it only is available during a user's particular session – Rob Terrell Feb 09 '21 at 21:29
-
do the following sessionStorage.setItem('test', 'hello') and close your browser once it is set in session storage – Rob Terrell Feb 09 '21 at 21:30
-
but it also deletes it after I close a tab, I want it to be deleted only when the whole browser closes – Dasto Feb 09 '21 at 21:33
-
if that's the case why are you using local storage then... – Rob Terrell Feb 09 '21 at 21:35
-
what should I use then? – Dasto Feb 09 '21 at 21:37
-
if you absolutely must use it.... here's something that might help https://stackoverflow.com/questions/9943220/how-to-delete-a-localstorage-item-when-the-browser-window-tab-is-closed – Rob Terrell Feb 09 '21 at 21:37
-
I don't necessarily need to use it I just want the item to be deleted after the browser closes and not after the tab closes – Dasto Feb 09 '21 at 21:38
-
it's somewhat difficult to detect a tab closing or a browser closing in javascript i think the stack over flow i sent might point you in a decent direction – Rob Terrell Feb 09 '21 at 21:39
-
1you are right, thanks for your help – Dasto Feb 09 '21 at 21:40