[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.
<head>
<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++)
init[i]();
}
function addBodyOnload(funct)
{
init[init.length] = funct;
}
</script>
</head>
<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.');
}
addBodyOnload(myOnLoadFunction);
</tip>
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168
More information about the thelist
mailing list