localStorage

Jump to: navigation, search

localStorage


W3C Proposed Recommendation

Summary

Provides a Storage object for an origin.

Property of apis/web-storage/Storage

Syntax

Note: This property is read-only.

var result = object.localStorage;

Return Value

Returns an object of type Object.

Examples

JavaScript

if (window.localStorage) { // checks if browser support localStorage
  if (localStorage['testKey']) { // checks if value exists
    console.log('Value exist on page load in localstorage for key testKey : ', localStorage['testKey']);
  }
  localStorage['testKey'] = 'Hi again!'; // stores value in localstorage
}
else {
 console.log('your browser dont support localstorage');
}

Notes

The localStorage "property" provides an instance of a storage area object, to which the Storage object's properties and methods are applied.


Related specifications

Specification Status Related Changes
W3C Web Storage Specification W3C Recommendation

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 23.0
16.0
8.0
12.1
5.1

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support 2.1
7.0
?
?
?
?
Unsupported
3.2

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: Windows Internet Explorer API reference Article