Last active
March 5, 2018 19:19
-
-
Save pankajpatel/281fc5e2e5ea769bd2e0 to your computer and use it in GitHub Desktop.
Browser Storage Example with JavaScript https://time2hack.com/2014/12/browser-storage-and-angularjs/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( window.Storage ){ | |
/* | |
* Get the values previously stored | |
*/ | |
//get the `user` key stored in the session storage | |
//this will show the value if stored otherwise 'undefined' | |
console.log( sessionStorage.getItem('user') ); | |
//get the `user` key stored in the local storage | |
//this will give 'undefined' | |
console.log( localStorage.getItem('user') ); | |
/* | |
* Store the new values | |
*/ | |
//store key `user` in the session storage | |
sessionStorage.setItem('user', 'pankaj'); | |
//store the key `user` in the local storage | |
localStorage.setItem('user', 'Time to Hack'); | |
//get the `user` key stored in the session storage | |
//this will show the value 'pankaj' | |
console.log( sessionStorage.getItem('user') ); | |
//get the `user` key stored in the local storage | |
//this will show the value 'Time to Hack' | |
console.log( localStorage.getItem('user') ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment