Skip to content

Instantly share code, notes, and snippets.

@engleek
Created May 19, 2011 09:19
Show Gist options
  • Select an option

  • Save engleek/980461 to your computer and use it in GitHub Desktop.

Select an option

Save engleek/980461 to your computer and use it in GitHub Desktop.
Localstorage snippet
if (typeof(localStorage) == 'undefined' ) {
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
} else {
try {
localStorage.setItem("name", "Hello World!"); //saves to the database, "key", "value"
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded!'); //data wasn’t successfully saved due to quota exceed so throw an error
}
}
document.write(localStorage.getItem("name")); //Hello World!
localStorage.removeItem("name"); //deletes the matching item from the database
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment