Actually I working on a project which need a situation, in which after deleting browser history, then it should only clear local storage of current opened tab, it should keep as it is other tabs local storage data
Asked
Active
Viewed 298 times
0
-
Are you developing a Chrome extension? A web page can't control what happens when the user deletes their browser history. – Josh Lee Feb 26 '18 at 13:51
-
@Josh Lee thanks, I am developing angular application is there any way? – omi 27 Feb 26 '18 at 14:00
-
If the user chooses to delete their browser history, there is absolutely nothing the web developer can do about that. – Josh Lee Feb 26 '18 at 14:17
1 Answers
0
Just like the answers to How to delete a localStorage item when the browser window/tab is closed?
All you need to do:
localStorage.removeItem(key);
Remove the specific key which you want to remove for that particular tab.
Or you will clear the whole localStorage using
localStorage.clear();

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

BooToo
- 11
- 1
- 2
-
Thanks@BooToo, but I want to clear local Storage only after cntl+shift+delete - > Clear History or through history -> Clear History, is it possible? – omi 27 Feb 26 '18 at 12:00
-
That is only possible when you are on the webpage ie the website you are developing so that you will listen to keypress event which in turn will clear your localStorage . Look at a [fiddled](https://jsfiddle.net/LLbygsmf/3/) example of your request. I hope it helps you. – BooToo Feb 27 '18 at 01:21