知道如何检查HTML5 localstorage数据存储中的剩余存储空间吗?
答案 0 :(得分:10)
答案 1 :(得分:2)
默认的localStorage分配大小为:5Mb
var allocated = 5;
var total = 0;
for(var x in localStorage){
var amount = (localStorage[x].length * 2) / 1024 / 1024;
total += amount;
}
var remaining = allocated - total;
console.log( "Used: " + total + " MB");
console.log( "Remaining: " + remaining + " MB");
答案 2 :(得分:0)
您可以在检测到浏览器后实现“名义限制”的查找表,并从中减去localStorage中已有内容的键值对。
答案 3 :(得分:-1)
默认为5兆字节。 如果存储空间超过5兆字节,它将抛出“QUOTA_EXCEEDED_ERR”异常。