设置"dataURL"的值超出了配额 [英] Setting the value of 'dataURL' exceeded the quota
问题描述
我有一个JavaScript代码,可将字符串保存到本地存储中,字符串大小为400000,
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);
我从chrome中打开html文件,在一台计算机上我可以在另一台计算机上确定
I open the html file from chrome, in one computer its OK in the other computer i get
未捕获的QuotaExceededError:无法在上执行'setItem' '存储':设置'dataURL'的值超出了配额.
Uncaught QuotaExceededError: Failed to execute 'setItem' on 'Storage': Setting the value of 'dataURL' exceeded the quota.
在这台计算机上,我允许保存的字符串长度不超过100000个字符. 两台计算机使用相同的Chrome版本35.0.1916.114 m 为什么?
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?
推荐答案
当您的浏览器达到最大限制时,它将引发此错误 无法在存储"上执行"setItem":设置"的值超出了配额.
When your browser reaches to maximum limit it will throw this error Failed to execute 'setItem' on 'Storage': Setting the value of '' exceeded the quota.
- 您可以这样处理
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
}
这篇关于设置"dataURL"的值超出了配额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!