首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >子域的HTML5 localStorage大小限制

子域的HTML5 localStorage大小限制
EN

Stack Overflow用户
提问于 2010-05-01 03:55:19
回答 3查看 79.8K关注 0票数 77

HTML5的localStorage数据库通常是有大小限制的--每个域的标准大小是5或10MB。这些限制是否可以通过子域规避(例如,example.com、hack1.example.com和hack2.example.com都有自己的5MB数据库)?标准中是否有规定父域是否可以访问其子域数据库的内容?我找不到任何东西,我可以看到无论哪种方式都可以这样做的论点,但似乎必须有一些标准模型。

EN

回答 3

Stack Overflow用户

发布于 2012-01-17 21:09:36

下面是一个非常详细的测试结果,其中涵盖了大量的桌面和移动浏览器:http://dev-test.nemikor.com/web-storage/support-test/

这证实了这个错误报告:http://code.google.com/p/chromium/issues/detail?id=58985#c15

基于您可以存储的字符串长度,您只能依赖2.5MB,而不是5MB。

票数 14
EN

Stack Overflow用户

发布于 2010-08-27 21:39:58

当我问"Is 5MB the de facto limit for W3C Web Storage?“的时候,我错过了这个问题,但我得到的答案基本上是一样的。如果你想了解更多信息,我在我的问题中确实链接到了一些特定于浏览器的限制。

票数 9
EN

Stack Overflow用户

发布于 2016-05-27 23:55:46

要获得50MB的存储空间,请使用以下代码

// 1. paste this line in your code
!function(){function e(t,o){return n?void(n.transaction("s").objectStore("s").get(t).onsuccess=function(e){var t=e.target.result&&e.target.result.v||null;o(t)}):void setTimeout(function(){e(t,o)},100)}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!t)return void console.error("indexDB not supported");var n,o={k:"",v:""},r=t.open("d2",1);r.onsuccess=function(e){n=this.result},r.onerror=function(e){console.error("indexedDB request error"),console.log(e)},r.onupgradeneeded=function(e){n=null;var t=e.target.result.createObjectStore("s",{keyPath:"k"});t.transaction.oncomplete=function(e){n=e.target.db}},window.ldb={get:e,set:function(e,t){o.k=e,o.v=t,n.transaction("s","readwrite").objectStore("s").put(o)}}}();

// 2. Setting values
ldb.set('nameGoesHere', 'value goes here');

// 3. Getting values - callback is required because the data is being retrieved asynchronously:
ldb.get('nameGoesHere', function (value) {
  console.log('And the value is', value);
});

https://github.com/DVLP/localStorageDB

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2747285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档