Setting the value of 'dataURL' exceeded the quota

前端 未结 5 848
[愿得一人]
[愿得一人] 2020-12-16 09:28

I have a JavaScript code which save string to the Local storage, the string size is 400000,

var dataURL = canvas.toDataURL(\"image/jpg\").toString();
localSt         


        
5条回答
  •  太阳男子
    2020-12-16 10:04

    When your browser reaches to maximum limit it will throw this error Failed to execute 'setItem' on 'Storage': Setting the value of '' exceeded the quota.

    • You can handle it like this

     try {
         var count = 100;
         var message = "LocalStorageIsNOTFull";
         for (var i = 0; i <= count; count + 250) {
             message += message;
             localStorage.setItem("stringData", message);
             console.log(localStorage);
             console.log(count);
         }
    
     }
     catch (e) {
         console.log("Local Storage is full, Please empty data");
         // fires When localstorage gets full
         // you can handle error here or empty the local storage
     }

提交回复
热议问题