この翻訳は不完全です。英語から この記事を翻訳 してください。
localStorage プロパティはローカルの Storage オブジェクトにアクセスすることができます。 localStorage は sessionStorage によく似ています。唯一の違いは、localStorage に保存されたデータには保持期間の制限はなく、sessionStorage に保存されたデータはセッションが終わると同時にクリアされてしまう(ブラウザが閉じられたとき)ことです。
Syntax
myStorage = localStorage;
Value
Storage オブジェクトを返します。
Example
以下のスニペットでは現在のドメインのローカル Storage オブジェクトにアクセスし、Storage.setItem() を利用してデータを追加しています。
localStorage.setItem('myCat', 'Tom');
Note: 詳細な使用例は Using the Web Storage API の記事を参照してください。
Specifications
| Specification | Status | Comment |
|---|---|---|
| Web Storage The definition of 'localStorage' in that specification. |
勧告 |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| localStorage | 4 | 3.5 | 8 | 10.50 | 4 |
| sessionStorage | 5 | 2 | 8 | 10.50 | 4 |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 2.1 | ? | 8 | 11 | iOS 3.2 |
すべてのブラウザは localStorage と sessionStorage に対する容量変更ができるようになっています。詳しくはこちらを参照してください。
Note: Starting with iOS 5.1, Safari Mobile stores localStorage data in the cache folder, which is subject to occasional clean up, at the behest of the OS, typically if space is short. Safari Mobile's Private Browsing mode also prevents writing to localStorage entirely.