Skip to content

Instantly share code, notes, and snippets.

@anoxic
Created December 31, 2013 16:45
Show Gist options
  • Select an option

  • Save anoxic/8199386 to your computer and use it in GitHub Desktop.

Select an option

Save anoxic/8199386 to your computer and use it in GitHub Desktop.
// From: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
// SESSION STORAGE
sessionStorage.setItem('fullname', 'John Paul'); // defining the session variable
alert("Your name is: " + sessionStorage.getItem('fullname')); // accessing it
alert("Hello " + sessionStorage.fullname); // another way of accessing the variable
sessionStorage.removeItem('fullname'); // finally unset it
sessionStorage.clear(); // removes all keys
// LOCAL STORAGE
localStorage.setItem('fullname', 'John Paul'); // defining the localStorage variable
alert("Your name is: " + localStorage.getItem('fullname')); // accessing it
alert("Hello " + localStorage.fullname); // another way of accessing the variable
localStorage.removeItem('fullname'); // finally unset it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment