Safari的html5 localStorage錯誤:“ QUOTA_EXCEEDED_ERR:DOM異常22:試圖向存儲中添加超出配額的內容”
顯然,這是設計使然。當Safari(OS X或iOS)處于私有瀏覽模式時,它似乎localStorage可用,但是嘗試調用setItem會引發異常。
store.js line 73'QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.'
發生的事情是該窗口對象仍在localStorage全局命名空間中公開,但是當您調用時setItem,將拋出此異常。的所有呼叫都將removeItem被忽略。
我相信最簡單的解決方法(盡管我尚未測試過此跨瀏覽器)將更改功能isLocalStorageNameSupported()以測試您是否還可以設置一些值。
function isLocalStorageNameSupported() { var testKey = ’test’, storage = window.sessionStorage; try {storage.setItem(testKey, ’1’);storage.removeItem(testKey);return localStorageName in win && win[localStorageName]; } catch (error) {return false; }}解決方法
我的webapp在ios Safari私人瀏覽中出現javascript錯誤:
JavaScript:錯誤
未定義
QUOTA_EXCEEDED_ERR:DOM異常22:試圖向存儲中添加內容…
我的代碼:
localStorage.setItem(’test’,1)
相關文章:
