D
David Otton
Hi, I'm seeing a difference in behaviour between
window.onload = f();
and
<body onload="f();">
Specifically, window.onload appears to fire before all the elements of
the page have been rendered. As the difference is consistent across
IE/Moz/Opera, I'm assuming it's deliberate - can anyone point me
towards where this behaviour of window.onload is defined in the
documentation? TIA.
Example code follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function countTags(){
var allTags = document.getElementsByTagName("*");
var str = "# of tags: " + allTags.length + "\n";
alert (str);
}
window.onload = countTags();
</script>
</head>
<body onload="countTags();">
<p>This is some dummy text</p>
<p>The quick brown fox jumps over the lazy dog</p>
<p>One Two Three Four Five</p>
<p><button onclick="countTags();">Count tags</button></p>
</body>
</html>
window.onload = f();
and
<body onload="f();">
Specifically, window.onload appears to fire before all the elements of
the page have been rendered. As the difference is consistent across
IE/Moz/Opera, I'm assuming it's deliberate - can anyone point me
towards where this behaviour of window.onload is defined in the
documentation? TIA.
Example code follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function countTags(){
var allTags = document.getElementsByTagName("*");
var str = "# of tags: " + allTags.length + "\n";
alert (str);
}
window.onload = countTags();
</script>
</head>
<body onload="countTags();">
<p>This is some dummy text</p>
<p>The quick brown fox jumps over the lazy dog</p>
<p>One Two Three Four Five</p>
<p><button onclick="countTags();">Count tags</button></p>
</body>
</html>