From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/storage/getitem/index.html | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 files/ja/web/api/storage/getitem/index.html (limited to 'files/ja/web/api/storage/getitem/index.html') diff --git a/files/ja/web/api/storage/getitem/index.html b/files/ja/web/api/storage/getitem/index.html new file mode 100644 index 0000000000..249dd1ad12 --- /dev/null +++ b/files/ja/web/api/storage/getitem/index.html @@ -0,0 +1,141 @@ +--- +title: Storage.getItem() +slug: Web/API/Storage/getItem +tags: + - API + - Method + - Reference + - Storage + - Web Storage +translation_of: Web/API/Storage/getItem +--- +

{{APIRef("Web Storage API")}}

+ +

{{domxref("Storage")}} インターフェイスの getItem() メソッドはキーの名称を渡すと、そのキーに対する値を返します。

+ +

構文

+ +
var aValue = storage.getItem(keyName);
+
+ +

引数

+ +
+
keyName
+
値を取り出したいキーの名称を持つ {{domxref("DOMString")}}。
+
+ +

戻り値

+ +

キーに対する値を持つ {{domxref("DOMString")}}。キーが存在しない場合は null が返ります。

+ +

+ +

以下の関数はローカルストレージから 3 個のデータアイテムを取り出して、その値を使用してページのカスタムスタイルを設定します。

+ +
function setStyles() {
+  var currentColor = localStorage.getItem('bgcolor');
+  var currentFont = localStorage.getItem('font');
+  var currentImage = localStorage.getItem('image');
+
+  document.getElementById('bgcolor').value = currentColor;
+  document.getElementById('font').value = currentFont;
+  document.getElementById('image').value = currentImage;
+
+  htmlElem.style.backgroundColor = '#' + currentColor;
+  pElem.style.fontFamily = currentFont;
+  imgElem.setAttribute('src', currentImage);
+}
+ +
+

注記: 実際の例として、Web Storage Demo をご覧ください。

+
+ +

仕様

+ + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('Web Storage', '#dom-storage-getitem', 'getItem()')}}{{Spec2('Web Storage')}}
+ +

ブラウザ実装状況

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
機能ChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
localStorage43.5810.504
sessionStorage52810.504
+
+ +
+ + + + + + + + + + + + + + + + + + + +
機能AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
基本サポート2.1{{CompatUnknown}}811iOS 3.2
+
+ +

すべてのブラウザで、localStorage および sessionStorage が受け入れる容量は異なります。さまざまなブラウザのストレージ容量を報告しているページがあります。

+ +
+

注記: iOS 5.1 より Safari Mobile は localStorage データを cache フォルダに保存しており、概して空き容量が少ない場合に OS の要求により、時々クリーンアップを受けます。

+
+s +

関連情報

+ + -- cgit v1.2.3-54-g00ecf