HTML5 allows you to store data on your local web browser

If you remember Google Gears, there was a feature (Local Database API) allowing to store data on your local web browser. But since HTML5 has emerged into supporting such a feature, Google has decided to retire its Google Gears.

To store data on the local web browser, you just need to use the function localStorage. But not every browser supports the function, it’s currently said to be supported by web browsers including Safari 4+, Mobile Safari (iPhone/iPad), Firefox 3.5+, Internet Explorer 8+ and Chrome 4+.

Using localStorage is easy, you just use a few functions below such as “setItem” is to set a value to a local browser, “getItem” is to return the value of the stored variable by its name, and “removeItem” is to remove it by its name.

And you can always check if it’s supported by your web browser as shown in the following JavaScript.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
}

This is typically like using a HashMap or Hashtable in Java programming but it isn’t like using any RDBMS where you can fire SQL. At the moment, we’re not too sure if Google Gears’ SQLLite is available or not in HTML5. We’ll update you while we learn along.

via html5tutorial

Enter your email address to subscribe our newsletter or feed for FREE:

Delivered by FeedBurner


Bookmark with:

[Delicious]    [Digg]    [Reddit]    [Facebook]    [StumbleUpon]

1 Response to “HTML5 allows you to store data on your local web browser”


  1. 1 Use HTML5 Canvas to draw and manipulate images | AjaxApp.com

Leave a Reply

You must login to post a comment.