I have a on page oad event that checks my manifest status, and if there is a change it asks the user to reload. However, I'm trying to bind a <button>
to manually check if there is a status on noupdate
. I can't seem to get this to work, here's my code:
window.addEventListener('load', function(e) {
if (window.applicationCache) {
window.applicationCache.addEventListener('updateready', function(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
// Swap it in and reload the page to get the new hotness.
window.applicationCache.swapCache();
if (confirm('A new version of this App is available. Load it now?')) {
window.location.reload();
}
} else {
// no manifest change..
}
}, false);
// if there is no update, display a message
window.applicationCache.addEventListener('noupdate', function(e) {
alert('App is up to date. ');
}, false);
}
}, false);
// check for a update each hour
setInterval(function () { window.applicationCache.update(); }, 3600000);
My function detecting noupdate
essentially fires my alert on page load without a hitch, but If I use it in a function tied to a button..
<a href="javascript:refresh();" data-theme="a" data-role="button"
data-icon="arrow-r" data-inline="true">Refresh</a>
<script>
function refresh() {
if (window.applicationCache) {
window.applicationCache.addEventListener('updateready', function(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
// Swap it in and reload the page to get the new hotness.
window.applicationCache.swapCache();
if (confirm('A new version of this App is available. Load it now?')) {
window.location.reload();
}
} else {
// no manifest change..
}
}, false);
// if there is no update, display a message
window.applicationCache.addEventListener('noupdate', function(e) {
alert('App is up to date. ');
}, false);
}
}
</script>
It does not get the noupdate status...