HTML and CSS Reference
In-Depth Information
Table 7-6. Local Storage Methods and Properties
API Method
Description
localStorage.clear()
Clears all data in the local storage
localStorage.setItem(key, value)
Sets a key value pair in local storage
localStorage.getItem(key)
Gets an item from local storage based on its
key
localStorage.key(0)
Gets an item from local storage based on its
index value; you can get the last item in
local storage by calling
localStorage.key(localStorage.length)
localStorage.removeItem(key)
Removes an item from local storage based
on its key
localStorage.length
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: " john.seagate@hello.com",
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.
XUI
jQuery Mobile
Sencha Touch
 
Search WWH ::




Custom Search