Session storage is a type of web storage that allows you to store key-value pairs in a web browser and maintain their values across multiple browser tabs or windows. The data stored in session storage is specific to the current session and is deleted when the user closes the tab or browser window.
- Store data in session storage:
- Retrieve data from session storage:
var data = sessionStorage.getItem("key");
- Remove data from session storage:
- Clear all data from session storage:
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.