Skip to content

Instantly share code, notes, and snippets.

@danesparza
Created May 16, 2011 03:58
Show Gist options
  • Save danesparza/973917 to your computer and use it in GitHub Desktop.
Save danesparza/973917 to your computer and use it in GitHub Desktop.
HTML 5 local storage - Javascript
// First, make sure our browser supports HTML 5 local storage
if (typeof(localStorage) == 'undefined' )
{
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
}
else
{
try
{
// saves to the database using key/value
localStorage.setItem('name', 'Hello World!');
}
catch (e)
{
if (e == QUOTA_EXCEEDED_ERR)
{
// data wasn’t successfully saved due to quota exceed so throw an error
alert('Quota exceeded!');
}
}
// Write out the item from local storage:
document.write(localStorage.getItem('name'));
//deletes the matching item from the database
localStorage.removeItem('name');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment