Auto refresh and autoload JS

Posted under » JavaScript on 22 March 2013

Let's say you want to refresh the page every 3 seconds. There are many ways to do this. This is but just one way.

 window.onload = function() {
setTimeout("window.location.reload();", 30000);

There are 3 parts to this.

  1. window.onload - which stays in the memory
  2. setTimeout - timer to repeat
  3. window.location.reload() - same page reload

To execute a JavaScript function, say sortList, immediately after a page has been loaded

 <body onload="sortList()"> 

If you don't want to clutter your body tag, you can put this at the end of your JS, eg.

window.onload = sortList();

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data