Javascript: onload

Published: Tuesday, 20 December 2005

Executing javascript upon loading of a page

This can be done by an onload attribute in the body element

<script type="text/javascript" language="Javascript">
function runMeAtStart() {
  alert('loading...');
}
</script>

..
..

<body onLoad="runMeAtStart();">
..

Alternatively, you can set onload to the function you can to call on startup:

<script type="text/javascript" language="Javascript">
  function runMeAtStart() {
    alert('loading...');
  }

  onload = runMeAtStart;
</script>
..
..
<body>
..