Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error: QuotaExceededError #8

Merged
merged 1 commit into from
May 19, 2017
Merged

Conversation

YoringChen
Copy link

当用户打开 “隐私模式/无痕浏览时”,处理QuotaExceededError

@jaywcjlove
Copy link
Owner

@Joey-93 什么浏览器,浏览器版本。

@YoringChen
Copy link
Author

@jaywcjlove ios下,打开无痕浏览就会出现这个错,只有手机上能复现

@jaywcjlove
Copy link
Owner

果然有问题,但是你加上这个也解决不了问题诶。 @Joey-93

@YoringChen
Copy link
Author

@jaywcjlove
可以保证程序能跑下去,只是关闭掉本地存储的功能。
sessionStorage出现同样情况 :( ,不过storejs只用到了localStorage,所以只补了localStorage。

@jaywcjlove jaywcjlove merged commit 8af2bcf into jaywcjlove:master May 19, 2017
@cbbfcd
Copy link
Contributor

cbbfcd commented Dec 18, 2018

所以,可以使用一个对象来继续完成存储功能吗?

(function () {
  function isSupported() {
    var item = 'localStoragePollyfill';
    try {
      localStorage.setItem(item, item);
      localStorage.removeItem(item);
      return true;
    } catch (e) {
      return false;
    }
  }

  if (!isSupported()) {
    try {
      Storage.prototype._data = {};

      Storage.prototype.setItem = function (id, val) {
        return this._data[id] = String(val);
      };

      Storage.prototype.getItem = function (id) {
        return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
      },

      Storage.prototype.removeItem = function (id) {
        return delete this._data[id];
      },

      Storage.prototype.clear = function () {
        return this._data = {};
      }
    } catch (e) {
      console.error('localStorage pollyfill error: ', e);
    }
  }
}());

如果需要,我准备提个 PR。

@jaywcjlove
Copy link
Owner

使用一个对象来继续完成存储功能吗? 这个是什么意思呢?
@cbbfcd

@cbbfcd
Copy link
Contributor

cbbfcd commented Dec 18, 2018

@jaywcjlove 就如上面代码中所表示的,不是只是让程序不会报错,而是创建一个对象,重载setItem 等方法,将数据存进这个对象中。

@jaywcjlove
Copy link
Owner

@cbbfcd 不支持的时候将数据存入对象中。这个是个好想法,可以提交一个 RP

@cbbfcd
Copy link
Contributor

cbbfcd commented Dec 18, 2018

ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants