[thelist] Friday Freebie

Joshua Olson joshua at waetech.com
Fri Oct 22 12:09:35 CDT 2004

Hopefully this helps somebody out.

<tip type="JavaScript" author="Joshua Olson">
I just restumbled across some code I wrote to dynamically add events to the
document's onload handler that should be completely cross-browser (for JS
enabled browsers)... and I mean COMPLETELY... as in it works on a Mac,
Mozilla, IE, Opera, etc.

    <script language="JavaScript" type="text/javascript">
      var init = new Array();
      init[0] = new Function("{}");
      function initBody()
        var i;
        for (i = 0; i < init.length; i++)
      function addBodyOnload(funct)
        init[init.length] = funct;
  <body onload="initBody();">

  If you want to add another function to execute when the page is loaded,
follow this example:

  function myOnLoadFunction()
    alert('hello, world.');


Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list