The sessionStorage object stores the data for only one session. The data is deleted when the user closes the browser window.
See also session-storage local-storage
The sessionStorage
Object
The sessionStorage
object is equal to the localStorage
object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.
Only plain-text values can be stored. Arrays, hashes, numbers, strings and booleans can be stored by using JSON.stringify(value)
. Then, to get the original value when reading the value, use JSON.parse(stringified_value)
.
Example
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.";