Skip to content

Instantly share code, notes, and snippets.

@danesparza
Created October 1, 2010 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danesparza/606702 to your computer and use it in GitHub Desktop.
Save danesparza/606702 to your computer and use it in GitHub Desktop.
//  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