PHP前端开发

如何在HTML中找到localStorage的大小?

百变鹏仔 4个月前 (09-21) #HTML
文章标签 大小

localStorage 用于跨多个会话保存信息。它的最大大小为 5MB。

示例

您可以尝试运行以下代码片段来检查分配的大小 -

var sum = 0;// loop for sizefor(var i in localStorage) {   var amount = (localStorage[i].length * 2) / 1024 / 1024;   sum += amount;   document.write( i + " = " + amount.toFixed(2) + " MB");}document.write( "Total = " + sum.toFixed(2) + " MB");