本文介绍了HTML5 localStorage错误与Safari:“QUOTA_EXCEEDED_ERR:DOM例外22:尝试向存储中添加超出配额的内容”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的代码: localStorage.setItem('test',1) 解决方案显然这是设计。当Safari(OS X或iOS)处于隐私浏览模式时,似乎 localStorage 可用,但试图调用 setItem store.js line 73 QUOTA_EXCEEDED_ERR:DOM异常22:尝试是为超过配额的存储添加了一些东西。 会发生什么情况是窗口对象仍然暴露 localStorage 在全局命名空间中,但是当您调用 setItem 时,会抛出此异常。任何对 removeItem 的调用都将被忽略。 我相信最简单的修复方法(尽管我没有测试过这个跨浏览器然而)会改变函数 isLocalStorageNameSupported()来测试你也可以设置一些值。 https://github.com/marcuswestin/store.js/issues/42 函数isLocalStorageNameSupported() { var testKey ='test',storage = window.sessionStorage; 尝试 { storage.setItem(testKey,'1'); storage.removeItem(testKey); 返回win&& amp;& amp;&赢得[localStorageName]; } catch(error) { return false; } } My webapp have javascript errors in ios safari private browsing:my code:localStorage.setItem('test',1) 解决方案 Apparently this is by design. When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage is available, but trying to call setItem throws an exception.store.js line 73"QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota."What happens is that the window object still exposes localStorage in the global namespace, but when you call setItem, this exception is thrown. Any calls to removeItem are ignored.I believe the simplest fix (although I haven't tested this cross browser yet) would be to alter the function isLocalStorageNameSupported() to test that you can also set some value.https://github.com/marcuswestin/store.js/issues/42function 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; }} 这篇关于HTML5 localStorage错误与Safari:“QUOTA_EXCEEDED_ERR:DOM例外22:尝试向存储中添加超出配额的内容”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 00:46