【问题标题】:iOS Safari Private Browsing localStorage and sessionStorage Support?iOS Safari 隐私浏览 localStorage 和 sessionStorage 支持?
【发布时间】:2016-06-07 01:43:20
【问题描述】:

我在 StackOverflow 上发现了一些关于使用 iOS Safari 隐私浏览和sessionStoragelocalStorage 解决特定功能的问题。但我还没有找到明确的资源来表明 iOS Safari 在隐私浏览时对 sessionStoragelocalStorage 的支持。

对此有什么支持,或者 Apple 是否有任何特定资源表示此功能?普遍的共识是,如果没有 polyfill,localStorage 根本不受支持,sessionStorage 也是如此吗?

非常感谢!

【问题讨论】:

    标签: javascript ios html safari


    【解决方案1】:

    我认为没有任何针对 iOS 的特定资源,但这里是 Apple 的官方文档:

    https://developer.apple.com/library/safari/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html

    这个 StackOverflow 问题也非常有用:

    QuotaExceededError: Dom exception 22: An attempt was made to add something to storage that exceeded the quota

    一般来说,解决sessionStoragelocalStorage 时,请尝试在打开Web Inspector 的手机上使用Safari 进行本地开发。祝你好运:)

    【讨论】:

      【解决方案2】:

      是的,sessionStoragelocalStorage 也是如此。

      Paul Irish 有一篇优秀的 Gist 解释了这个问题的历史:

      https://gist.github.com/paulirish/5558557

      如果您只需要其中一个,最好的解决方案:

      function isLocalStorageEnabled() {
        try {
            var mod = '__storage_test__';
            localStorage.setItem(mod, mod);
            localStorage.removeItem(mod);
            return true;
        } catch(e) {
            return false;
        }
      }
      

      或者,为了使其适用于两者,MDN 推荐的解决方案更通用: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

      function storageAvailable(type) {
          try {
              var storage = window[type];
              var x = '__storage_test__';
              storage.setItem(x, x);
              storage.removeItem(x);
              return true;
          }
          catch(e) {
              return false;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2014-11-20
        • 1970-01-01
        • 2013-09-22
        • 2016-04-12
        • 1970-01-01
        • 1970-01-01
        • 2018-01-25
        • 2018-06-18
        • 1970-01-01
        相关资源
        最近更新 更多