Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

TopicContents
clear

Removes all key/value pairs from the Web Storage area.

constructor

Returns a reference to the constructor of an object.

getItem

Retrieves the current value associated with the Web Storage key.

key

Retrieves the key at the specified index in the collection.

length

Retrieves the length of the key/value list.

remainingSpace

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

removeItem

Deletes a key/value pair from the Web Storage collection.

setItem

Sets a key/value pair.

Web Storage Events

Internet Explorer fires events when data in a storage area is updated, so that information can synchronized between multiple instances of the browser or tabs.

The following events are supported:

  • onstorage
  • onstoragecommit

onstorage

The onstorage event is fired in a document when a storage area changes. All documents sharing the same session context, and those that are currently displaying a page from the same domain or subdomain where local storage is being committed, receive the event.

If the target document object is not currently active, Internet Explorer does not fire any events.

onstoragecommit

Internet Explorer uses XML files to store local storage. The onstoragecommit event fires when a local storage is written to disk.

Security and Privacy

The data stored in local storage is much more public than that stored in cookies, which can be limited to a certain path within a domain. Even picking a hard-to-guess key won't provide any privacy because the Storage object provides a way to enumerate them.

Here are some things to consider:

 

Top-Level Browsing Context and Hostname

Access to the session storage area is restricted by the top-level browsing context. In Internet Explorer, a new browsing context is created for every tab. Script running in one top-level browsing context has no access to storage created in another. Sites can add data to the session storage, and it will be accessible to  any page from that hostname opened in the same window.

Important  The port and protocol/scheme are not evaluated as a part of this check.

 

Origin Determines Storage Limits

Disk quota limits are imposed against the domain of the page that sets the value, rather than the domain where the value is being set. This prevents malicious scripts from using up the storage quota of a related domain. It also prevents such scripts from using random subdomains to store unrestricted amounts of data.

Storage size is calculated as the total length of all key names and values, and a single storage area can contain up to 10 million bytes. The remainingSpace property is used to determine the available storage space.

 

Clearing the Storage Areas

Session state is released as soon as the last window to reference that data is closed. However, users can clear storage areas at any time by selecting Delete Browsing History from the Tools menu in Internet Explorer, selecting the Cookies check box, and clicking OK. This clears session and local storage areas for all domains that are not in the Favorites folder and resets the storage quotas in the registry. Clear the Preserve Favorite Site Data check box to delete all storage areas, regardless of source.

To delete key/value pairs from a storage list, iterate over the collection with removeItem or use clear to remove all items at once. Keep in mind that changes to a local storage area are saved to disk asynchronously.

 

Related topics