zoukankan      html  css  js  c++  java
  • 移动端浏览器隐私模式/无痕模式使用本地存储localStorage/sessionStorage的问题

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

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

    • localStorage对象仍然存在
    • 但是setItem会报异常:QuotaExceededError
    • getItem和removeItem直接忽略

    Safari中控制台截图

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

    function isLocalStorageSupported() {
        var testKey = 'test',
            storage = window.sessionStorage;
        try {
            storage.setItem(testKey, 'testValue');
            storage.removeItem(testKey);
            return true;
        } catch (error) {
            return false;
        }
    }
    
  • 相关阅读:
    在dotnet下用c#编写下载器(转载)
    hdu 1176
    hdu 1231(最大连续子序列)
    hdu 2571
    hdu 1087(最大递增子序列)
    hdu 1506(dp)
    hdu 1069
    hdu 2084(数塔经典dp)
    hdu 2602(01背包)
    hdu 1505
  • 原文地址:https://www.cnblogs.com/fanyong/p/4564549.html
Copyright © 2011-2022 走看看