Skip to content

Instantly share code, notes, and snippets.

@pankajpatel
Last active March 5, 2018 19:19
Show Gist options
  • Save pankajpatel/281fc5e2e5ea769bd2e0 to your computer and use it in GitHub Desktop.
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/
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