Introduction
- window.localStorage: stores data with no expiration date so the data will persist even if the user closes the tab
- window.sessionStorage: stores data for the one session and the data would be lost when the user closes the tab
localStorage.setItem("lastname", "Singh");
sessionStorage.firstname= "Ratnesh";
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function SetName()
- {
- if(typeof(Storage) !== "undefined")
- {
- localStorage.setItem("lastname", "Singh");
- sessionStorage.setItem("firstname", "Ratnesh");
- }
- }
- function GetName()
- {
- if(typeof(Storage) !== "undefined")
- {
- document.getElementById("divName").innerHTML = sessionStorage.getItem("firstname")+' ' +localStorage.getItem("lastname");
- }
- }
- function RemoveName()
- {
- if(typeof(Storage) !== "undefined")
- {
- localStorage.clear();
- //localStorage.removeItem("lastname");
- }
- }
- </script>
- </head>
- <body>
- <p><button onclick="SetName()" type="button">Set Name</button>
- <button onclick="GetName()" type="button">GetName</button>
- <button onclick="RemoveName()" type="button">Remove Name</button></p>
- <div id="divName"></div>
- </body>
- </html>


Gowtham RajamanickamPosted Mar 18, 2015, 3:40 AM
good show...
Gowtham RajamanickamPosted Mar 18, 2015, 3:40 AM
good show..
Rahul Kumar SaxenaPosted Mar 17, 2015, 1:01 AM
good Work..