开发者

HTML5 LocalStorage: How Much Space Do I Have Left?

A开发者_如何转开发ny idea how to check the remaining storage space in an HTML5 localstorage data store?


I don't know if this helps, but you can check if it full.

“QUOTA_EXCEEDED_ERR” is the exception that will get thrown if you exceed your storage quota of 5 megabytes.

And this other answer might be related.


Default localStorage allocated size is: 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");


5 megabytes by default. It will throw “QUOTA_EXCEEDED_ERR” exception if storage exceeds more than of 5 megabytes.


You could implent a lookup table of "nominal limits" after detecting the browser, and substract the key-value pair size of what's already in the localStorage from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜