【问题标题】:Is there a limit to the key length for localStorage?localStorage 的密钥长度有限制吗?
【发布时间】:2012-01-10 20:55:01
【问题描述】:

在使用 localStorage 时,密钥是否有任何限制(最多为可用的本地存储量)?

即我可以这样做吗:

localStorage.setItem("pretend that this is a 1MB string", "whatever"); 

【问题讨论】:

    标签: html local-storage


    【解决方案1】:

    是的,每个域的限制为 5MB。 您的字符串可以任意长。但是,总使用量必须低于 5 MB。

    http://dev.w3.org/html5/webstorage/

    http://www.stackoverflow.com/questions/2747285/html5-localstorage-restrictions-and-limits

    【讨论】:

    • OP 询问的密钥长度超过了总存储量。这些链接并没有特别回答这个问题。你是说密钥长度是无限的,只要不超过总的 5 MB?
    • @ParchedSquid 刚刚在 IE9、Chromium 30、Firefox 25 上测试过;键可以有任何长度,只要键+值对的总大小在存储的边界内(大约 5MB)。用于测试的代码:localStorage.clear();localStorage.setItem(new Array(5e6).join(' '),'');localStorage.key(0).length;
    • 我在FF24中快速测试,结果相同。感谢您的确认。
    • 在 iOS 8.1 (iPhone 4S) 上的 UIWebView 中测试,限制为 ~2.6MB
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2015-10-22
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多