Here is an example of a more reliable method. This works even when
there is an onload handler assigned in the body. To see it in action,
put the following in a text file file on your hard disk nameded (e.g.)
test_onload.html and open that file in your browser. IE may need to be
coaxed to run active content off your hard disk (as if that was more
dangerous than running active content off the net).
<html><head><title>On Load tester</title>
<script type="text/javascript">
//<![CDATA[
function onLoad1() {
alert("This is onLoad1.");
}
if (window.attachEvent) {
window.attachEvent("onload", function() {
onLoad1(); // Internet Explorer
});
} else {
window.addEventListener("load", function() {
onLoad1(); // Firefox and others.
}, false);
}
//]]>
</script>
</head><body></body></html>
If I had a onload handler named in the body element, it would run
first. Then my attached/added handlers will run in the order they were
attached/added.
I tested this in Firefox 1.0.6 and in Internet Explorer 6.0 on a fully
patched Win XP box.