LocalStorage method for obtaining the maximum storage size


(function() { if(!window.localStorage) { console.log('当前浏览器不支持localStorage!') } var test = '0123456789'; var add = function(num) { num += num; if(num.length == 10240) { test = num; return; } add(num); } add(test); var sum = test; var show = setInterval(function(){ sum += test; try { window.localStorage.removeItem('test'); window.localStorage.setItem('test', sum); console.log(sum.length / 1024 + 'KB'); } catch(e) { alert(sum.length / 1024 + 'KB超出最大限制'); clearInterval(show); } }, 0.1) })()

It runs directly above method in the browser console.

Pro-test Chrome browser localStorage largest 5120kb, namely 5M.

Guess you like

Origin www.cnblogs.com/djjlovedjj/p/11202195.html