Window sessionStorage Atribute
- Nakaraang Pahina scrollY
- Susunod na Pahina self
- Bumalik sa nakaraang Level Object ng Window
Pagsasakop at Paggamit
localStorage
at sessionStorage
Ating propyedade ay nagpapahintulot sa Web browser na mag-iimbak ng mga pares ng key/value.
sessionStorage
Objects only store data for one session (data will be deleted when the browser tab is closed).
Tip:See Also localStorage PropertyThis property stores data without an expiration date. Data is not deleted when the browser is closed and will be available the next day, a week, or a year later.
Example
Example 1
Create a sessionStorage name/value pair with name="lastname" and value="Smith", then retrieve the value of "lastname" and insert it into the element with id="result":
// Store sessionStorage.setItem("lastname", "Smith"); // Retrieve document.getElementById("result").innerHTML = sessionStorage.getItem("lastname");
Example 2
The following example calculates the number of times the user has clicked the button in the current session:
if (sessionStorage.clickcount) { sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1; } else { sessionStorage.clickcount = 1; } document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
Syntax
window.sessionStorage
Syntax for saving data to sessionStorage:
sessionStorage.setItem("key", "value");
Syntax for reading data from sessionStorage:
var lastname = sessionStorage.getItem("key");
Syntax for deleting data from sessionStorage:
sessionStorage.removeItem("key");
Syntax for deleting all saved data from sessionStorage:
sessionStorage.clear();
Technical Details
Return Value: | Obhekyto ng Storage |
---|
Suporta ng Browser
Ang numero sa talahanayan ay nagtutukoy sa unang bersyon ng browser na ganap na sumusuporta sa katangian.
Atribute | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
sessionStorage | 4.0 | 8.0 | 3.5 | 4.0 | 11.5 |
- Nakaraang Pahina scrollY
- Susunod na Pahina self
- Bumalik sa nakaraang Level Object ng Window