獲取localStorage最大存儲大小的方法



(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) })()

直接在瀏覽器控制台運行上面的方法。

親測Chrome瀏覽器中localStorage最大5120kb,即5M。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM