I'm not surprised, since in my experience, a global solution doesn't always suffice. I've seen ways to try to offer an easy way out but they have always failed me. It depends on what you are doing.
I reckon we should always try first to do it by body.onload. If that doesn't work, try the window.onload suggestions given in this thread.
If that doesn't work, try a global solution but don't expect it to always work.
There are really crazy things going on in this area (of course, there is a good reason for everything). For instance, ...
Why does this work?
Code:
<body onload="hm();mySoundObj1.TGotoAndPlay('/clk1','start');" onunload="sm();" background="../img/bg/bgggreylines.gif">
<div id="watermarklogo" style="position:absolute;"></div>
<script language="javascript">
<!--
var logowidth=85
var logoheight=18
var logoimage=new Image(logowidth,logoheight)
logoimage.src="../img/next2.gif"
var alttext="Click Here"
var visibleduration=0
var Hoffset=11
var Voffset=39
var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var watermark_obj=ie? document.all.watermarklogo : document.getElementById? document.getElementById("watermarklogo") : document.watermarklogo
function insertimage(){
if (ie||document.getElementById)
watermark_obj.innerHTML='<a href="test2n.html" target="_self"><img src="'+logoimage.src+'" width="'+logowidth+'" height="'+logoheight+'" border=0 alt="'+alttext+'"></a><br><a href="test2l.html" target="_self"><img src="../img/prev2.gif" width="85" height="18" alt="Click Here" title="Click Here" border="0" align="middle"></a>';
else if (document.layers){
watermark_obj.document.write('<a href="test2n.html" target="_self"><img src="'+logoimage.src+'" width="'+logowidth+'" height="'+logoheight+'" border=0 alt="'+alttext+'"></a><br><a href="test2l.html" target="_self"><img src="../img/prev2.gif" width="85" height="18" alt="Click Here" title="Click Here" border="0" align="middle"></a>');
watermark_obj.document.close();
}
}
function positionit(){
var dsocleft=ie? document.body.scrollLeft : pageXOffset
var dsoctop=ie? document.body.scrollTop : pageYOffset
var window_width=ie? document.body.clientWidth : window.innerWidth-20
var window_height=ie? document.body.clientHeight : window.innerHeight
if (ie||document.getElementById){
watermark_obj.style.left=parseInt(dsocleft)+parseInt(window_width)-logowidth-Hoffset
watermark_obj.style.top=parseInt(dsoctop)+parseInt(window_height)-logoheight-Voffset
}
else if (document.layers){
watermark_obj.left=dsocleft+window_width-Hoffset-logowidth
watermark_obj.top=dsoctop+window_height-logoheight-Voffset
}
}
function hidewatermark(){
if (document.layers)
watermark_obj.visibility="hide"
else
watermark_obj.style.visibility="hidden"
clearInterval(watermarkinterval)
}
function beingwatermark(){
watermarkinterval=setInterval("positionit()",50)
insertimage()
if (visibleduration!=0)
setTimeout("hidewatermark()",visibleduration*1000)
}
if (ie||document.getElementById||document.layers)
window.onload=beingwatermark(); // don't know why this onload works - it shouldn't, but it produces the images required
// End -->
</script>
<div align="center">
Forget what it does, and don't try to answer it (I value your time!), but it is the only way I can get all these onloads (three of them) working. But everyone believes a body onload always prevents a windows.onload from happening. Big BS obviously.
Nothing I have read anywhere really explains it - but, of course, an explanation is out there somewhere.
Anyhow, if you can be bothered, love to see your solution!