HTML and CSS Reference
In-Depth Information
Table 7-6. Local Storage Methods and Properties
API Method
Clears all data in the local storage
localStorage.setItem(key, value)
Sets a key value pair in local storage
Gets an item from local storage based on its
Gets an item from local storage based on its
index value; you can get the last item in
local storage by calling
Removes an item from local storage based
on its key
Returns the number of items in local storage
For example, if you wanted to store an object with a user's name, e-mail
address, and contact phone number, you would create something like this:
var user = {name: "John Seagate", email: "",
contactNumber: "012345678910"}
localStorage.setItem('user', JSON.stringify(user));
To retrieve the item, you would use the following code:
var user = JSON.parse(localStorage.getItem('user'));
JavaScript Libraries for Mobile
JavaScript libraries can help with some of the heavy lifting of any type of front-
end development. They can help with providing a consistent API for anything
from DOM manipulation to all the way through to the kitchen sink. There are
three libraries that will be used as examples in this chapter.
jQuery Mobile
Sencha Touch
Search WWH ::

Custom Search