有没有一种方法可以在Google Chrome中增加localStorage的大小,以避免QUOTA_EXCEEDED_ERR:DOM异常22

| 我编写了一个webapp,可让您将图像存储在localStorage中,直到您点击保存为止(因此,如果信号较差,它可以脱机工作)。 当localStorage达到5MB时,Google Chrome浏览器在javascript控制台日志中产生错误:   未捕获的错误:QUOTA_EXCEEDED_ERR:DOM异常22 如何在Google Chrome浏览器上增加localStorage配额的大小?     
已邀请:
您不能,它的硬连线为5MB。这是Chrome开发人员的设计决定。 在Chrome浏览器中,默认情况下,Web SQL数据库和缓存清单也具有较低的限制,但是如果您为Chrome App Store打包应用程序,则可以增加它们。 另请参阅管理HTML5离线存储-Google Chrome。     
5MB是一个硬限制,这是愚蠢的。 IndexedDB给您〜50MB,这是更合理的。为了更易于使用,请尝试Dexie.js https://github.com/dfahlander/Dexie.js 更新: 对于我的简单键值而言,Dexie.js实际上仍然是一个过大的功能,因此我编写了这个简单得多的脚本https://github.com/DVLP/localStorageDB 有了这个,你有50MB,可以获取和设置类似的值
// Setting values
ldb.set(\'nameGoesHere\', \'value goes here\');

// Getting values - callback is required because the data is being retrieved asynchronously:
ldb.get(\'nameGoesHere\', function (value) {
  console.log(\'And the value is\', value);
});
复制/粘贴下面的行,以便上面示例中的
ldb.set()
ldb.get()
可用。
!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)}}}();
    
配额由用户设置,他希望为每个网站允许多少空间。 因此,由于目的是限制网页,因此网页不能改变限制。 如果存储空间不足,则可以提示用户增加本地存储。 要确定存储空间是否不足,可以通过保存对象然后将其删除来探查本地存储大小。     
您不能,但是如果将JSON保存在localStorage中,则可以使用库来压缩数据,例如:https://github.com/k-yak/JJLC 演示:http://k-yak.github.io/JJLC/     

要回复问题请先登录注册