25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

254<br />

CHAPTER 10 ■ CREATING <strong>HTML</strong>5 OFFLINE WEB APPLICATIONS<br />

}<br />

} catch (e) {<br />

applicationCache.onerror();<br />

}<br />

onload = function(e) {<br />

// Check for required browser features<br />

if (!window.applicationCache) {<br />

log("<strong>HTML</strong>5 Offline Applications are not supported in your browser.");<br />

return;<br />

}<br />

}<br />

if (!navigator.geolocation) {<br />

log("<strong>HTML</strong>5 Geolocation is not supported in your browser.");<br />

return;<br />

}<br />

if (!window.localStorage) {<br />

log("<strong>HTML</strong>5 Local Storage not supported in your browser.");<br />

return;<br />

}<br />

log("Initial cache status: " + showCacheStatus(window.applicationCache.status));<br />

document.getElementById("installButton").onclick = checkFor;<br />

<br />

log = function() {<br />

var p = document.createElement("p");<br />

var message = Array.prototype.join.call(arguments, " ");<br />

p.inner<strong>HTML</strong> = message;<br />

document.getElementById("info").appendChild(p);<br />

}<br />

Check for ApplicationCache Support<br />

In addition to the offline application cache, this example uses geolocation and local storage. We ensure<br />

that the browser supports all of these features when the page loads.<br />

onload = function(e) {<br />

// Check for required browser features<br />

if (!window.applicationCache) {<br />

log("<strong>HTML</strong>5 Offline Applications are not supported in your browser.");<br />

return;<br />

}<br />

if (!navigator.geolocation) {<br />

log("<strong>HTML</strong>5 Geolocation is not supported in your browser.");<br />

return;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!