html5 – localStorage何时清除?

前端之家收集整理的这篇文章主要介绍了html5 – localStorage何时清除?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望数据保存在localStorage多长时间。一般用户的localStorage数据将持续多长时间?如果用户不清除它,它将持续到浏览器重新安装?

这是否跨浏览器一致?

解决方法

localStorage也被称为Web存储,HTML5存储和DOM存储(这些都意味着相同的东西)。

localStorage类似于sessionStorage,除了存储在localStorage中的数据没有到期时间,而存储在sessionStorage中的数据在浏览会话结束时(即当浏览器关闭时)被清除。

localStorage在所有浏览器上都可用,但持久化并不一致。特别地,localStorage可以通过用户操作清除,并可能被无意中清除(谁会认为清除所有cookie也会清除localStorage?)。

在Firefox中,localStorage在满足以下三个条件时被清除:(a)用户清除最近的历史记录,(b)选择要清除的cookie,(c)时间范围为“Everything”

在Chrome中,localStorage会在满足以下条件时被清除:(a)清除浏览数据,(b)选择“Cookie和其他站点数据”,(c)时间段是“从开始”。在Chrome中,它现在也可以delete localStorage for one specific site

在IE中,清除localStorage:(a)工具 – Internet选项,(b)常规选项卡,(c)退出浏览历史记录,(d)确保“Cookie和网站数据” “),(e)考虑取消选中顶部的”保留收藏夹网站数据“

在Safari中:(a)单击Safari(b)首选项(c)选择隐私选项卡(d)单击删除所有网站数据(e)单击立即删除

Opera:尽管Opera网站上提供了关于localStorage的优秀文章,但我还没有找到清楚的(非程序化)指示,告诉用户如何清除localStorage。如果任何人发现,请在这个答案下面留下评论与参考链接

Opera dev site有一个很好的localStorage摘要

The current way of storing data on the client-side — cookies — is a
problem:

  • Low size: Cookies generally have a maximum size of around 4 KB,which
    is not much good for storing any kind of complex data

  • It’s difficult for cookies to keep track of two or more transactions on the same
    site,which might be happening in two or more different tabs

  • Cookies
    can be exploited using techniques such as cross site scripting,
    resulting in security breaches

Other (less popular) alternatives to
cookies include techniques involving query strings,hidden form
fields,flash based local shared objects,etc. Each with their own set
of problems related to security,ease of use,size restrictions etc.
So up until now we have been using pretty bad ways of storing data on
the user’s end. We need a better way,which is where Web Storage comes
in.

Web Storage

The W3C Web Storage specification was designed as a better way of
storing data on the client-side. It has two different types of
storage: Session Storage and Local Storage.

Both Session and Local Storage will typically be able to store around
5 MB of data per domain,which is significantly more than cookies.

资源:

https://dev.opera.com/articles/web-storage/

http://www.quirksmode.org/html5/storage.html

http://www.ghacks.net/2015/02/05/how-to-clear-web-storage-in-your-browser-of-choice/

https://nakedsecurity.sophos.com/2014/11/05/how-to-clear-out-cookies-flash-cookies-and-local-storage/

http://www.opera.com/dragonfly/documentation/storage/

DOMStorage article on MDN (written by John Resig)

http://ejohn.org/blog/dom-storage/

原文链接:https://www.f2er.com/html5/169617.html

猜你在找的HTML5相关文章