html safari错误,HTML5的本地存储的错误:“quota_exceeded_err Safari:DOM例外22:试图存储超过定额补充一下。”...

当Safari浏览器处于私密浏览模式时,localStorage会出现QUOTA_EXCEEDED_ERR错误,尝试设置项会抛出异常,而移除项操作则被忽略。这是因为Safari在这种模式下限制了localStorage的使用。解决办法是在检测localStorage是否可用时,不仅检查其存在,还需尝试设置和移除值来确保功能正常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Rubens Mariuzzoleiyonglin提出了一个问题:html5 localStorage error with Safari: “QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.”,或许与您遇到的问题类似。

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.

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;

}

}

希望本文对你有帮助,欢迎支持JavaScript中文网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值