Search code examples
javascriptajaxpage-refresh

Alternatives to using meta-refesh for updating a page


In the past, when I've covered events, I've used a meta-refresh with a 5 minute timer to refresh the page so people have the latest updates.

Realizing that this may not be the perfect way to do it (doesn't always work in IE, interrupts a person's flow, restarts things for people with screen readers, etc.) I'm wondering if there's any other way to do handle this situation.

Is it possible to have something like ajax check every few minutes if the html file on the server is newer and have it print a message saying "Update info available, click here to refresh"?

If that's crazy, how about a javascript that just counts down from 5 minutes and just suggests a refresh.

If anyone could point me to tutorials or code snippets I'd appreciate. I just play a programmer on TV. :-)


Solution

  • setInterval(function() {
      if (confirm("Its Been 5 Minutes. Would you like to refresh")) {
        window.location.reload(true);
        //Or instead of refreshing the page you could make an ajax call and determing if a newer page exists.  IF one does then reload.
    
      }
    }, 300000);