21
22

More than 5 years have passed since last update.

Safari ではプライベートブラウジング時に SessionStorage/LocalStorage に書き込めない

Last updated at Posted at 2013-09-06

正確には QUOTA_EXCEEDED_ERR 例外が発生する。

とりあえず以下のような関数を作って、判定すればよいのではないかと。

※ 9/8 コメントを受けて、コードを一部修正。

function isLocalStorageSupported() {
  if (!window.sessionStorage) return false;

  var testKey = 'test';
  try {
    window.sessionStorage.setItem(testKey, '1');
    window.sessionStorage.removeItem(testKey);
    return true;
  } catch (error) {
    return false;
  }
}
21
22
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
22