1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 移动端浏览器隐私模式/无痕模式使用本地存储localStorage/sessionStorage的问题

移动端浏览器隐私模式/无痕模式使用本地存储localStorage/sessionStorage的问题

时间:2021-02-28 07:21:48

相关推荐

移动端浏览器隐私模式/无痕模式使用本地存储localStorage/sessionStorage的问题

独角兽企业重金招聘Python工程师标准>>>

开发H5 webapp时经常需要使用本地存储,如localStorage和sessionStorage存储一些数据,相比最多能存4k的cookie相比,用起来很好用。但是localStorage在iOS Safari、chrome和UC浏览器中的隐私模式(也叫无痕模式)下无法使用,手机Safari浏览器中具体表现是:

localStorage对象仍然存在但是setItem会报异常:QuotaExceededErrorgetItemremoveItem直接忽略

Safari中控制台截图

判断浏览器是否支持localStorage的方法:

function isLocalStorageSupported() {var testKey = 'test',storage = window.sessionStorage;try {storage.setItem(testKey, 'testValue');storage.removeItem(testKey);return true;} catch (error) {return false;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。