Before HTML5 application data had to be stored in cookies,included in every request. Web storage is more secure and can stored large amount of data locally without affecting on web site performance.
- session object
window.sessionStorage
used to store data for one session and data lost when browser closed. - local object
window.localStorage
used to stroe data with no expiration date.
Before using storage check if browser support it or not
if(typeof(Storage)!==undefined){
//code to store data in web storage
}else{
alert("Sorry Browser Not Support Storage");
}
localStorage.setItem("Name","Ahmed");
or
localStorage.Name="Ahmed";
localStorage.getItem("Name");
or
localStorage.Name
;
localstorage.removeItem("Name");
I have been created a todo list application (CRUD) using localstorage you can download project. To know how you can use localStorage to store data locally.