HTML and CSS Reference
In-Depth Information
Table 8-2. Events of the applicationCache Object
Event
Description
checking
Raised when the browser detects a web page's manifest attribute.
downloading
Raised when the browser begins downloading files listed in an application's cache
manifest file.
progress
Raised periodically during the download process.
cached
Raised when an application has been downloaded successfully and cached on the local
machine.
updateready
Raised when the browser has successfully downloaded an updated version of a
previously cached application.
noupdate
Raised when the browser detects that no update is required for an already cached
application.
obsolete
Raised when the browser detects that the cache manifest of a previously cached
application is no longer available on the server.
error
Raised when there is an error during any of the other events.
To understand how you can use these events, let's wire some of them into the Clock application (see
Listing 8-11). The Clock application essentially uses these events to notify the end user about the
associated operations.
Listing 8-11. Using applicationCache Object Events
$(document).ready(function () {
...
$(applicationCache).bind("checking",NotifyUser);
$(applicationCache).bind("downloading", NotifyUser);
$(applicationCache).bind("progress", NotifyUser);
$(applicationCache).bind("cached", NotifyUser);
$(applicationCache).bind("updateready", NotifyUser);
$(applicationCache).bind("noupdate", NotifyUser);
$(applicationCache).bind("obsolete", NotifyUser);
$(applicationCache).bind("error", NotifyUser);
});
function NotifyUser(evt) {
alert(evt.type);
if (evt.type == 'updateready') {
if (confirm('An updated version of this application is available.' +
'Do you wish to use the new version now?'))
{
applicationCache.swapCache();
}
}
}
This code binds the applicationCache events listed in Table 8-1 to a common event handler function
NotifyUser() . The NotifyUser() function displays the event type ( checking , downloading , progress , and so
on). Notice the if block: if the event type is updateready , it means an updated version of the application is
available. In most cases, you want the user to use the updated version immediately. One way to
 
Search WWH ::




Custom Search