Local storage and Session storage
Local storage and session storage are part of web storage which itself is part of the HTML5 application.Local Storage
Stores data with no expiration date and this is the one we will be using because we want out to-do’s to stay on the page for as long as possible. Before HTML5 , application data had to be stored in cookies, included in every server request. Local 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 (at least 5MB) and information is never transferred to the server.Local storage is per domain. All pages, from one domain, can store and access the same data.Store
localStorage.setItem("lastname", "Smith");
Create a localStorage name/value pair with name="lastname" and value="Smith"Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
Retrieve the value of "lastname" and insert it into the element with id="result"Remove Item
localStorage.removeItem("lastname");
Remove the local storage "lastname" key
Session Storage
It is same as the local storage except
that it stores the data for one session.The data is deleted when the user closes the browser
window. The following is the example of using session storage.
Set
value
sessionStorage.setItem("Name","aaa");
Get value
sessionStorage.getItem("Name");
0 comments:
Post a Comment