有没有办法一次性删除localStorage的全部内容?
我有一个网络应用程序,可以将用户页面历史记录填充到本地存储中。咳咳。它应该是sessionStorage,我现在已经更改了它,以便它不会持续存在。
但这给我留下了一个有趣的问题:一个完整的本地存储被清空。我知道您可以在开发人员控制台中编辑存储来删除数据,但想象一下我出于某种原因想要使用 localStorage,并且在某些时候我想完全删除以编程方式放置在那里的数据内容。
我知道本地存储是特定于域的,所以这不应该成为问题 - 但我的问题是如何全局识别我的数据然后删除它?
是否有一个 js 表达式可以一次性删除我的数据?或者我是否坚持使用密钥的命名约定,然后使用正则表达式来选择所有密钥?
I have a web app that populates user page history into the local storage. Ahem. It should be sessionStorage, which I have now changed so that it doesn't persist.
But that left me with an interesting problem: a full localStorage to be emptied. I know you can edit the storage in the developer console to remove the data, but imagine I wanted to use localStorage for whatever reason, and at some point I wanted to completely delete the contents of data that I had placed there programmatically.
I understand local storage is domain specific so this should not be a problem - but my question is how do I globally identify my data and then delete it?
Is there a single js expression that I could use that will just wipe out my data in one hit? Or am I stuck with using naming conventions for my key and then using a reg-ex to select all the keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像这样简单:
规范:http://dev.w3.org/html5/ webstorage/#dom-storage-clear
As easy as:
Spec: http://dev.w3.org/html5/webstorage/#dom-storage-clear
是您要调用的方法,请参阅 http://php-html.net/ tutorials/html5-local-storage-guide/ 或 http://diveintohtml5.ep.io/storage.html
is the method call you are after see http://php-html.net/tutorials/html5-local-storage-guide/ or http://diveintohtml5.ep.io/storage.html