HTML and CSS Reference
In-Depth Information
When you put it all together, the code looks like this:
<script>
var editable = document.getElementById('editableList');
addEvent(editable, 'blur', function () {
localStorage.setItem('contenteditable', this.innerHTML);
document.designMode = 'off';
});
addEvent(editable, 'focus', function () {
document.designMode = 'on';
});
if (localStorage.getItem('contenteditable')) {
editable.innerHTML = localStorage.getItem('contenteditable');
}
</script>
This, of course, is just a bare-bones example of what's possible with this feature. Local storage
could be used for everything from a simple to-do list to an elaborate time-tracking application.
Local storage is supported by Safari 4+, Firefox 3.5+, Internet Explorer 8+, and Google Chrome 4+.
GeoLocaTion
The integration of GPS (Global Positioning System) into our everyday lives is one of the more amaz-
ing feats of modern technology. From driving directions in your car to nearby restaurant locators in
your cell phone, the ability to pinpoint a user's location — and send place-relevant information — is
quickly changing our world.
Now, with the HTML5 geolocation feature, your websites can join in the localizing revolution.
What good is geolocation? A great number of online sites are local businesses. Imagine searching for
a television repair shop and getting those closest to you at the top of the listing, automatically. Or
picture quickly identifying the nearest veterinarian while on vacation in an unfamiliar city. The pos-
sibilities for geolocation are enormous.
The HTML5 geolocation API is capable of retrieving your current IP (Internet Protocol) address. Though
this is not, in most cases, the same as your current exact location, generally it's pretty close. Even so,
some of you may be thinking, “But what if I don't want my location discovered — even the location of
my IP address host computer?” The contributors to the HTML5 specification had the same concerns
and made it imperative that browsers handle geolocation requests on an opt-in basis. In other words, a
browser must ask if you want to share your location before processing the function and uncovering it.
To retrieve a site visitor's location, you'll need JavaScript code to do the following:
A function that calls the
geolocation.getCurrentPosition() function where geolocation
is a navigator object.
A function that checks to make sure that the user has given his or her permission to share
their position. This function is most typically set up as an error handler that also checks to
Search WWH ::




Custom Search