Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

What is HTML Web Storage?

Web applications can store data locally within the user's browser with web storage.

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
Before HTML5, application data had to be stored in cookies, included in every server request. 
Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. 
Unlike cookies, the storage limit is far larger and information is never transferred to the server.
Which are HTML Web Storage Objects?
HTML web storage provides two objects for storing data on the client.
window.localStorage stores data with no expiration date window.sessionStorage   stores data for one session .
To check browser support for localStorage and sessionStorage use following code:
if (typeof(Storage) !== "undefined")
{
// code of localStorage/sessionStorage.
}
else
 { //  Web Storage Not supported. 
}

localStorage Object
It stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.
E.g:
//To Store data
localStorage.setItem("firstname", "Jack");
// To Retrieve data
document.getElementById("result").innerHTML= localStorage.getItem("firstname");

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 specific browser tab.
if (sessionStorage.clickcount)
{
 sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1; }
else
{
sessionStorage.clickcount = 1;
 }
document.getElementById("result").innerHTML = "Button is clicked" + sessionStorage.clickcount + " time(s) in this session.";
CONTINUE READING
Web Storage?
HTML
Ayesha
Tech writer at newsandstory