0

What does the following code mean? Especially the "if" section. Why does the alert only fire sometimes?

window.applicationCache.addEventListener('updateready', function(e) {
  if (window.applicationCache.status == window.applicationCache.UPDATEREADY)
    window.location.reload();

  alert('done');
}, false);

Any advice will be welcome.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Alex F
  • 183
  • 2
  • 14

1 Answers1

0

See comments inline:

function foo(e) 
  {
  /* If the status is UPDATEREADY, reload the page */
  if (window.applicationCache.status == window.applicationCache.UPDATEREADY)
    {
    window.location.reload();
    }

  /* Alert 'done' (reload has precedence) */ 
  alert('done');
  }

/* Add a new event which bubbles up and calls foo, but does not capture */
window.applicationCache.addEventListener('updateready', foo, false);

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265