AJAX - The Complete Reference

(avery) #1

546 Part III: Advanced Topics


updateOnlineStatus();
document.body.addEventListener("offline", updateOnlineStatus, false);
document.body.addEventListener("online", updateOnlineStatus, false);
};
</script></head>
<body>
<div id="status">Current status: <span id="state"> </span></div>
<div class="content"><h2>Firefox 3 Offline Tester</div>
</body>
</html>

You can see this simple example at http://ajaxref.com/ch10/connectionstatus.html,
and it is shown in action here.

In Firefox 3, you can indicate that a resource should be made available for offline
consumption simply by setting a <link> tag value like so:

<link rel="offline-resource"
href="http://ajaxref.com/ch10/offlineimage.gif" />

These items will be loaded after the onload event has fired for the page, similar to how
prefetching mechanisms work. However, we can programmatically control the process on
our own by calling navigator.offlineResources.add(), passing it a URL string of
what we are interested in saving:

navigator.offlineResources.add("http://ajaxref.com/ch10/offlineimage.gif");
Free download pdf