Created
May 19, 2011 09:19
-
-
Save engleek/980461 to your computer and use it in GitHub Desktop.
Localstorage snippet
This file contains hidden or 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 (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