SessionStorage is a type of web storage that allows you to store key-value pairs in a web browser. The data stored in session storage is specific to the current session or tab, and is deleted when the user closes the tab or browser window.
Here are the basic steps to use SessionStorage in JavaScript:
- Store data in SessionStorage:
sessionStorage.setItem("key", "value");
- Retrieve data from SessionStorage:
var data = sessionStorage.getItem("key");
- Remove data from SessionStorage:
sessionStorage.removeItem("key");
- Clear all data from SessionStorage:
sessionStorage.clear();
It’s important to note that data stored in session storage can only be accessed by scripts on the same origin as the data was stored. The maximum size of the data that can be stored in session storage varies between browsers, but is usually around 5-10 MB.
You can also use the length property to get the number of key-value pairs stored in session storage, and the key() method to retrieve the key at a specific index in the storage.
+ There are no comments
Add yours