本地存储在铬 [英] Local storage in chrome

查看:119
本文介绍了本地存储在铬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将字符串保存到本地存储的JavaScript代码,字符串大小为400000,

  var dataURL = canvas .toDataURL( 图像/ JPG)的toString(); 
localStorage.setItem(dataURL,dataURL);

我从chrome中打开html文件,在一台计算机中, p>


未捕获QuotaExceededError:未能在
'Storage'上执行'setItem':设置'dataURL'的值超过配额。 / p>

在此计算机中,我允许保存字符串长度不超过100000个字符。
这两台电脑都有相同的版本35.0.1916.114 m
为什么?

解决方案

当浏览器到达到最大限度,它会抛出这个错误
在'Storage'上执行'setItem'失败:设置''的值超过配额。


    您可以像这样处理它


  try {var count = 100; var message =LocalStorageIsNOTFull; for(var i = 0; i <= count; count + 250){message + = message; localStorage.setItem(stringData,message);的console.log(localStorage的);的console.log(计数); }} catch(e){console.log(本地存储已满,请清空数据); //当localstorage存满时//你可以在这里处理错误或清空本地存储}  


I have a JavaScript code which save string to the Local storage, the string size is 400000,

var dataURL = canvas.toDataURL("image/jpg").toString();
localStorage.setItem("dataURL", dataURL);

I open the html file from chrome, in one computer its OK in the other computer i get

Uncaught QuotaExceededError: Failed to execute 'setItem' on 'Storage': Setting the value of 'dataURL' exceeded the quota.

In this computer I allowed to save string length no more than 100000 chars. Both computers have the same chrome's Version 35.0.1916.114 m Why?

解决方案

rWhen your browser reaches to maximum limit it will throw this error Failed to execute 'setItem' on 'Storage': Setting the value of '' exceeded the quota.

  • You can handle it like this

 try {
     var count = 100;
     var message = "LocalStorageIsNOTFull";
     for (var i = 0; i <= count; count + 250) {
         message += message;
         localStorage.setItem("stringData", message);
         console.log(localStorage);
         console.log(count);
     }

 }
 catch (e) {
     console.log("Local Storage is full, Please empty data");
     // fires When localstorage gets full
     // you can handle error here or empty the local storage
 }

这篇关于本地存储在铬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆