LoginSignup
0
2

More than 5 years have passed since last update.

ローカル環境で、localStorageが使えるかの確認メモ

Posted at

localStorageが使える環境

ローカル環境で使えないのと、そのエラーハンドリングがうまくいかないことがあるので、以下のコードで調査したメモです。


try{
    if (window.localStorage) {
        console.log('LS can use !');
    }else{
        _c_('LS cannot use 1');
    }
} catch(e) {
    _c_('LS cannot use 2');
}

結果

環境 ブラウザ 結果
ローカルファイル(file:///C:/) Win10 Edge LS cannot use 2
ローカルファイル(file:///C:/) Win10 IE11 LS cannot use 1
ローカルファイル(file:///C:/) Win10 Chrome LS can use !
ネットワークフォルダ(\server-name\) Win10 Edge LS can use !
ネットワークフォルダ(\server-name\) Win10 IE11 LS can use !
ネットワークフォルダ(\server-name\) Win10 Chrome LS can use !
サーバー(http://) Win10 Edge LS can use !
サーバー(http://) Win10 IE11 LS can use !
サーバー(http://) Win10 Chrome LS can use !

使用可否の判別コードについて

Edgeでローカルファイルを開いたときは、try ~ catch でないと判別できず、エラーで止まります。

0
2
0

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
0
2