开发者

Is there a way to delete entire contents of localStorage in one go?

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?


As easy as:

localStorage.clear();

Spec: http://dev.w3.org/html5/webstorage/#dom-storage-clear


localStorage.clear();  

is the method call you are after see http://php-html.net/tutorials/html5-local-storage-guide/ or http://diveintohtml5.ep.io/storage.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜