HTML and CSS Reference
In-Depth Information
Yo u r m a n i f e s t :
CACHE MANIFEST
FALLBACK:
online.js offline.js
online.js contains:
setOnline(true);
offline.js contains:
setOnline(false);
In your application you have a function called testOnline that
dynamically creates a script element that tries to load the
online.js JavaScript fi le. If it succeeds, the setOnline(true)
code is run. If you are offline, behind the scenes the browser
falls back on the offline.js JavaScript fi le, which calls
setOnline(false) . From there, you might want to trigger the
applicationCache.update :
function testOnline(fn) {
var script = document.createElement('script')
script.src = 'online.js';
// alias the setOnline function to the new function that was
// passed in
window.setOnline = function (online) {
document.body.removeChild(script);
fn(online);
};
// attaching script node trigger the code to run
document.body.appendChild(script);
}
testOnline(function (online) {
if (online) {
applicationCache.update();
} else {
// show users an unobtrusive message that they're
¬ disconnected
}
});
 
Search WWH ::




Custom Search