zoukankan      html  css  js  c++  java
  • IOS下的safari下localStorage不起作用的问题

    我们的一个小应用,使用百度地图API获取到用户的坐标之后用localStorage做了下缓存,测试上线之后有运营同学反馈页面数据拉取不到,

    测试的时候没有发现问题,而且2台相同的iphone一台可以一台不行,最后定位到是localStorage有问题。

    但是为啥明明版本一样的2台手机一台可以一台不行呢?

    而且2台手机打印localStorage明明都是Object,奇怪了。

    在度娘上没找到答案,最后到google发现有人说是Private Browsing Mode引起的。然后查看IOS的safari没有发现隐私设置什么的

    后来点击右下角小框框发现有个无痕浏览的模式。MD,关闭后一切正常

    // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
    // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
    // to avoid the entire page breaking, without having to do a check at each usage of Storage.
    if (typeof localStorage === 'object') {
        try {
            localStorage.setItem('localStorage', 1);
            localStorage.removeItem('localStorage');
        } catch (e) {
            Storage.prototype._setItem = Storage.prototype.setItem;
            Storage.prototype.setItem = function() {};
            alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.');
        }
    }

    可以酱紫判断。提示用户关闭无痕模式。

    或者http://stackoverflow.com/questions/14555347/html5-localstorage-error-with-safari-quota-exceeded-err-dom-exception-22-an这里还有其他

    人写的一些方法,我没试过。各位可以试试

  • 相关阅读:
    机器学习中 margin loss 、hinge loss 和 ramp loss 的区别
    ML 论文中 用到的 temperature
    对一系列 pickle load 进行解包,只保留最后几个
    Linux 常用命令速览
    Numpy 的 dtype 和 astype 的区别
    远程配置 tensorflow 环境
    pytorch 的一些坑
    Conda 配置虚拟 pytorch 环境 和 Tensorflow 环境
    Ubuntu 远程离线配置 pytorch 运行环境
    3.Vue起步
  • 原文地址:https://www.cnblogs.com/honeybaobao/p/4798988.html
Copyright © 2011-2022 走看看