iOS Safari私密浏览localStorage和sessionStorage支持?

Aar*_*wer 7 javascript safari html5 ios

我在这里发现了一些问题,在计算器上解决与iOS的Safari浏览器隐私浏览和具体的功能sessionStoragelocalStorage.但我无法找到表明iOS Safari支持的私有资源sessionStoragelocalStorage私有浏览的权威资源.

对此有什么支持,还是来自Apple的任何特定资源表示此功能?普遍的共识是,localStorage如果没有填充物,根本没有支持,同样适用sessionStorage吗?

非常感谢!

the*_*ide 8

是的,这同样适用于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;
  }
}
Run Code Online (Sandbox Code Playgroud)

或者,为了使它适用于两者,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;
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 4

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

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

这个 StackOverflow 问题也非常有用:

QuotaExceededError:Dom 异常 22:尝试向存储添加超出配额的内容

一般来说,在求解sessionStorage和时localStorage,请尝试在打开 Web Inspector 的情况下使用手机上的 Safari 进行本地开发。祝你好运 :)