Packagewebstorage
Interfacepublic interface Storage

Introduced in: HTML 5 

The DOM Storage mechanism is a means through which string key/value pairs can be securely stored and later retrieved for use. The goal of this addition is to provide a comprehensive means through which interactive applications can be built (including advanced abilities, such as being able to work "offline" for extended periods of time).

sessionStorage sets fields on the window. When the window is closed, the session fields are lost, even if the site remains open in another window.

localStorage sets fields on the domain. Even when you close the browser, reopen it, and go back to the site, it remembers all fields in localStorage.

See also

W3C Web Storage Specification
Quirksmode: HTML5 compatibility - Local storage and session storage


Public Properties
 PropertyDefined By
  Web Storage length : Number
[read-only] Returns the number of key/value pairs currently present in the list associated with the object.
Storage
  Non-Standard remainingSpace : Number
[read-only] Retrieves the remaining memory space, in bytes, for the storage object.
Storage
Public Methods
 MethodDefined By
  
Web Storage clear():void
Empties the object of all key/value pairs, if there are any.
Storage
  
Web Storage getItem(key:DOMString):DOMString
NameGetter The getItem(key) method must return the current value associated with the given key.
Storage
  
Web Storage key(index:Number):DOMString
IndexGetter Returns the value at the specified index.
Storage
  
Web Storage removeItem(key:DOMString):void
NameDeleter The removeItem(key) method must cause the key/value pair with the given key to be removed from the list associated with the object, if it exists.
Storage
  
Web Storage setItem(key:DOMString, data:DOMString):void
NameSetter Adds the data based on the key name.
Storage
Property Detail
Web Storage lengthproperty
length:Number  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

Returns the number of key/value pairs currently present in the list associated with the object.


Implementation
    public function get length():Number

See also

remainingSpaceproperty 
remainingSpace:Number  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b

Non-standard (Microsoft)

Retrieves the remaining memory space, in bytes, for the storage object.

The current size of the storage area is calculated as the sum of the length of all key names and values.


Implementation
    public function get remainingSpace():Number

See also

Method Detail
Web Storage clear()method
public function clear():void

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

Empties the object of all key/value pairs, if there are any.

See also


Example
<button onclick="localStorage.clear()">Clear Stored Values</button>
Web Storage getItem()method 
public function getItem(key:DOMString):DOMString

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

NameGetter The getItem(key) method must return the current value associated with the given key.

Parameters

key:DOMString

Returns
DOMString

See also

Web Storage key()method 
public function key(index:Number):DOMString

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

IndexGetter Returns the value at the specified index.

Parameters

index:Number

Returns
DOMString

Throws
DOMException — INDEX_SIZE_ERR: May be raised if index is greater than or equal to the number of key/value pairs in the object.

See also

Web Storage removeItem()method 
public function removeItem(key:DOMString):void

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

NameDeleter The removeItem(key) method must cause the key/value pair with the given key to be removed from the list associated with the object, if it exists.

Parameters

key:DOMString — The name of the key, or the empty string.

See also

Web Storage setItem()method 
public function setItem(key:DOMString, data:DOMString):void

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5b4 Safari 3.0 Safari 3.1 Safari 4.0 Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0b
Introduced in: HTML 5 

NameSetter Adds the data based on the key name. If the key already exists, that data is updated with the new data.

Parameters

key:DOMString
 
data:DOMString


Throws
DOMException — QUOTA_EXCEEDED_ERR: May be raised if setting fails.

See also


Example
         sessionStorage.setItem('myKey', '...');
         sessionStorage['myKey'] = '...'; 
         sessionStorage.myKey = '...';