Java Reference
In-Depth Information
The HTML5 specification contains a number of APIs that help to gain access to the hard-
ware, such as cameras, batteries, geolocation, and the graphics card. Hardware evolves
quickly and APIs are frequently introduced to give developers access and control new fea-
tures that appear in the latest devices.
In this section, we'll look at some of the more popular APIs that are already supported in
most modern browsers; however, due to the ever-changing nature of most APIs, it is still
best practice to use object-detection tests before using any of the API methods.
HTML5 Web Storage
The Web Storage API provides a key-value store on the client's computer that is similar to
using cookies but has fewer restrictions, more storage capacity, and is generally easier to use.
This makes it perfect for storing information about users, as well as storing application-spe-
cific information that can then be used during future sessions. It's supported in all modern
browsers from Internet Explorer version 8 upwards, and each domain has its own separate
storage area.
The Web Storage API has some crucial differences with cookies:
• information stored is not shared with the server on every request
• information is available in multiple windows of the browser (but only if the domain
is the same)
• storage capacity limit is much larger than the 4KB limit for cookies [7]
If a browser supports the Web Storage API the window object will have a property called
localStorage , which is a native object with a number of properties and methods used to
store data. The information is saved in the form of key-value pairs and the values can only
be strings. There is also a sessionStorage object that works in the same way, although
the data is only saved for the current session.
Here is a basic example of storing information. To save a value locally, use:
Search WWH ::

Custom Search