getItem
Summary
Returns the current value associated with the given key.
Method of apis/web-storage/Storageapis/web-storage/Storage
Syntax
var = object.getItem(key);
Parameters
key
- Data-type
- String
The name of the key (a valid UTF-16 string, including the empty string).
Return Value
Returns an object of type StringString
Examples
This example creates a new localStorage item (a timestamp) and sets it with a unique key, then executes a function, then retrieves the timestamp by its key and reports it.
window.localStorage.setItem('timestamp', (new Date()).getTime());
doSomethingElse();
startTime = window.localStorage.getItem('timestamp');
alert("The doSomethingElse function was called at: " + startTime);
Notes
Any valid UTF-16 string, including the empty string, is a valid key name. If the specified key does not exist in the list associated with the object, then this method returns null. Attempts to read or write a secured item from script running in the context of an unsecured URL are not permitted.
Related specifications
- W3C Web Storage Specification
- W3C Editor’s Draft
Attributions
Microsoft Developer Network: Windows Internet Explorer API reference Article