Window sessionStorageProperty
Examples
Use sessionStorage to create a local storage name/value pair, name="lastname" value="Smith", then retrieve the value of "lastname" and insert it into the element with id="result":
Try it Yourself »
Definition and Usage
The localStorage and sessionStorage properties allow storing key/value pair data in the browser.
sessionStorage is used to temporarily save data for the same window (or tab), and this data will be deleted after the window or tab is closed.
Tip:If you want to keep data after the browser window is closed, you can use the localStorageproperty. This data object has no expiration time; it can be used today, next week, or next year, unless you manually delete it.
Browser Support
The numbers in the table indicate the first browser version that supports the property.
| Property | |||||
|---|---|---|---|---|---|
| sessionStorage | 4.0 | 8.0 | 3.5 | 4.0 | 11.5 |
Syntax
window.sessionStorage
Syntax for saving data:
sessionStorage.setItem("key", "value");
Syntax for reading data:
var lastname = sessionStorage.getItem("key");
Syntax for deleting data of a specified key:
sessionStorage.removeItem("key");
Delete all data:
sessionStorage.clear();
Technical Details
| Return Value: | A storage object |
More Examples
Example
The following example is used to record the number of times a button is clicked:
Try it Yourself »
JavaScript Storage Object