75
78

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

localStorage基本操作

Last updated at Posted at 2013-04-08

この記事を書いてから既に5年以上経っているのですが今年になってもいいねをいただく事があるので、注意喚起のため更新します。
詳細は以下の記事を参照いただけると。
HTML5のLocal Storageを使ってはいけない(翻訳)
https://techracho.bpsinc.jp/hachi8833/2019_10_09/80851

// localStorageが使用出来るかチェック
if (!window.localStorage) {
    alert("お使いのブラウザはlocalstorageに対応してません。");
}

// localStorageに値を保存
function setItem(key, val) {
    window.localStorage.setItem(key, val);
}

// localStorageから値を取得
function getItem(key) {
    return window.localStorage.getItem(key);
}

// localStorageに保存されている、あるkeyの値を削除する
function removeItem(key) {
    window.localStorage.removeItem(key);
}

// localStorageに保存されているすべての値を削除する
function clear() {
    window.localStorage.clear();
}
75
78
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
75
78

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?