iOS Safari私密浏览模式是否支持localStorage和sessionStorage?

7

我在StackOverflow上找到了一些关于iOS Safari私密浏览和sessionStoragelocalStorage的特定功能的问题。但我尚未找到明确的资源,说明iOS Safari在私密浏览时对sessionStoragelocalStorage的支持。

这方面有哪些支持或者苹果有没有指出这个功能的具体资源?普遍认为,localStorage没有任何支持,除非使用polyfill补丁,那么sessionStorage是否也是一样呢?

非常感谢!

2个回答

9

是的,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;
    }
}

4
我认为在iOS方面没有特定的资源,但这里是苹果公司的官方文档: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时,您可以在手机上使用Safari进行本地开发,并打开Web检查器。祝好运:)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接