最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - iOS Safari Private Browsing localStorage and sessionStorage Support? - Stack Overflow

programmeradmin5浏览0评论

I have found a few questions here on StackOverflow addressing specific functionality with iOS Safari Private Browsing and sessionStorage and localStorage. But I haven't been able to find a definitive resource denoting the support that iOS Safari has for sessionStorage and localStorage when Private Browsing.

What support is there for this or is there any specific resource from Apple denoting this functionality? The general consensus is that localStorage is not at all supported without a polyfill, does the same goes for sessionStorage?

Thank you so much!

I have found a few questions here on StackOverflow addressing specific functionality with iOS Safari Private Browsing and sessionStorage and localStorage. But I haven't been able to find a definitive resource denoting the support that iOS Safari has for sessionStorage and localStorage when Private Browsing.

What support is there for this or is there any specific resource from Apple denoting this functionality? The general consensus is that localStorage is not at all supported without a polyfill, does the same goes for sessionStorage?

Thank you so much!

Share Improve this question edited Sep 14, 2017 at 17:51 tvanfosson 533k102 gold badges700 silver badges799 bronze badges asked Feb 24, 2016 at 16:31 Aaron BrewerAaron Brewer 3,66719 gold badges51 silver badges79 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Yes, same goes for sessionStorage and localStorage.

There is an excellent Gist by Paul Irish explaining the history of the issue:

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

Best solution if you only need one of them:

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

Or, to make it work for both, the MDN-remended solution is more-generic: https://developer.mozilla/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;
    }
}

I don't think there is any specific resource for iOS, but here's Apple's official documentation:

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

And this StackOverflow question is pretty useful as well:

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

In general, when solving for sessionStorage and localStorage, try actually developing locally with Safari on your phone with Web Inspector open. Good luck :)

发布评论

评论列表(0)

  1. 暂无评论