extension: session storage
Session storage
Session storage
One of the issues with a running JavaScript code in a multi page website, is that all your JavaScript data is lost when click on a nav bar button.
One of the issues with a running JavaScript code in a multi page website, is that all your JavaScript data is lost when click on a nav bar button.
HTML v5 has a feature called sessionStorage which enables a program to save and retrieve data across multiple html files.
HTML v5 has a feature called sessionStorage which enables a program to save and retrieve data across multiple html files.
IE - without using sessionStorage:
IE - without using sessionStorage:
- index.html runs a program which asks the user for input and saves it to a variable in memory.
- the user then clicks on the nav bar to go to another web page; all the program's variables are now lost...
IE - using sessionStorage:
IE - using sessionStorage:
- index.html runs a program which asks the user for input and saves it to sessionStorage.
- the user then clicks on the nav bar to go to another web page; all the program's variables are now lost, HOWEVER, the program can retrieve the data from sessionStorage.
sessionStorage in JavaScript has the following calls (APIs):
sessionStorage in JavaScript has the following calls (APIs):
setItem(name, value) – set the value for a name
removeItem(name) – remove the name-value pair identified by name.
getItem(name) – get the value for a given name.
key(index) – get the name of the value in the given numeric position.
clear() – remove all values in the sessionStorage