English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
sessionStorage properties allow you to access a session Storage object. It should be noted that the data stored in sessionStorage or localStorage is specific to the protocol of the page.
thesessionStorage'sRead-only properties allow you to access a Session Storageobjects.
The localStorage and sessionStorage properties allow you to store keys/Value pairs are stored in the Web browser.
The sessionStorage object stores data for a browser session. When the user closes a specific browser tab, the data will be deleted.
sessionStorage is similar to localStorage; the only difference is that the data stored in localStorage does not have an expiration time, while the data stored in sessionStorage is cleared when the page session ends.
Page sessions are maintained throughout the browser's open period, and the original page session is preserved even after reloading or restoring the page. When a page is opened in a new tab or window, the context of the top-level browser session is copied as the context of the new session, which is different from the way session cookies operate.
You can find more information on ourHTML5 in the Web Storage APILearn more about sessionStorage.
window.sessionStorage
To store dataSaveSyntax for saving to sessionStorage:
sessionStorage.setItem("key", "value");
from sessionStorage ReadSyntax of data:
var name = sessionStorage.getItem("key");
from sessionStorage DeleteSyntax of data:
sessionStorage.removeItem("key");
from sessionStorage Delete allSyntax of saved data:
sessionStorage.clear();
// Storage sessionStorage.setItem("name", "Parrot"); // Value retrieval document.getElementById("demo").innerHTML = sessionStorage.getItem("name");Test See‹/›
The above code creates a sessionStorage named using name="name" and value="Parrot"./Value pair.
Then retrieve the value of 'name' and insert it into the element with id="demo".
Name/Values are always stored as strings, and you can convert them to another format as needed.
Note:Once the browser window is closed, sessionStorage will be cleared.
The numbers in the table specify the first browser version that fully supports the sessionStorage property:
Properties | |||||
sessionStorage | 4 | 3.5 | 11.5 | 4 | 9 |
Return Value: | OneStorageObject, used to access the session storage space of the current source |
---|
The following example sets a session variable and accesses the variable:
if (sessionStorage.hits) { sessionStorage.hits = Number(sessionStorage.hits) + 1; } else { sessionStorage.hits = 1; }Test See‹/›
Window (Window) Reference:window.localStorage property
HTML Tutorial:HTML5 Web Storage API