javascript - Error: The quota has been exceeded. on Safari IOS 10 - Stack Overflow

I'm getting this error on my iPhone's safari, when doing localStorage.setItem('user'

I'm getting this error on my iPhone's safari, when doing localStorage.setItem('user',some string here):

Error: The quota has been exceeded.
setItem@[native code]

It is not private mode! What other circumstances can make localStorage not work?

I'm getting this error on my iPhone's safari, when doing localStorage.setItem('user',some string here):

Error: The quota has been exceeded.
setItem@[native code]

It is not private mode! What other circumstances can make localStorage not work?

Share Improve this question edited Aug 29, 2019 at 2:52 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Nov 29, 2016 at 18:47 ice_vitaice_vita 791 gold badge2 silver badges7 bronze badges 1
  • Possible duplicate of html5 localStorage error with Safari: "QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota." – Alex W Commented Apr 28, 2017 at 20:22
Add a ment  | 

2 Answers 2

Reset to default 2

I created this class to help get around private browsing. However, storage will be blown away when you refresh the browser.

const data = {};
let hasLocalStorage = false;

if (localStorage) {
  try {
    const x = 'storageTest';
    localStorage.setItem(x, x);
    localStorage.removeItem(x);
    hasLocalStorage = true;
  } catch (e) {
    hasLocalStorage = false;
  }
}

class StorageUtilities {
  setItem(key, value) {
    if (hasLocalStorage) {
      localStorage.setItem(key, value);
    } else {
      data[key] = value;
    }
  }

  getItem(key) {
    if (hasLocalStorage) {
      return localStorage.getItem(key);
    }
    return data[key];
  }

  removeItem(key) {
    if (hasLocalStorage) {
      localStorage.removeItem(key);
    } else {
      data[key] = null;
    }
  }
}

const storageUtilities = new StorageUtilities();

export default storageUtilities;

Actually it was Private mode. Looks like it is enabled by default on new iphones.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742393271a4435437.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信