Auto-refresh a webpage with html

I'm currently working on an app that has a dashboard-style page that we needs to be automatically refreshed. After digging around, I realised that the code to do this was ridiculously trivial:

// Ok, document.ready is jQuery - but you get the gist
$(document).ready(function() {
  setTimeout(function() {
    location.href = location.href;
    }, 10000); 
  // 10000 == 10 seconds
  // Change this if you want a different refresh period
});

UPDATE

Frederic in the comments mentioned a way nicer way of doing this, without needing Javascript. Simple add a refresh meta tag in the header of your html.

e.g.

<meta http-equiv="refresh" content="10" />

(This example refreshes after 10 seconds.)

The browser automatically knows how to handle it, and you don't need any messy javascript!

Find more information about meta refresh here: http://en.wikipedia.org/wiki/Meta_refresh



Subscribe via RSS

Back to all blog posts