开发者

JavaScript onload function call suddenly produces "Object expected"

The following onload function call was working:


    <script type="text/javascript">   
    function frameloaded() {  
       if (parent.leftframe) {  
          parent.leftframe.reportRightFrameReloaded();  
       }  
    }  
    </script>      
    </head>    
    <body onload="frameloaded();">  
 .... etc.

until I added an external javascript reference

 
    <script type="text/javascript" src="sorttable.js"></script< 

immediately before it. Then suddenly it started giving me "Object expected" in IE (I have IE8) and simply stopped working in Firefox (3.6.3). I figured there was a duplicate function name in the included file, so I gave it a random name and it still failed. I tried using


    onload="this.frameloaded();"   

an开发者_如何学编程d


    onload="document.frameloaded();"   

with no luck.

I tried moving my function above the included statement, but just got an empty frame.

Any ideas? Thanks!


@Hamish was right. The problem was in sorttable.js. It uses window.onload, which conflicted with my BODY onload. In sorttable.js, there were several window.onload statements within some elaborate logic, so I couldn't just use the recommended solution in such cases, which would be to trigger all the required onload functions in the BODY onload event.

Instead, my solution, which I am not entirely comfortable with, is to put the contents of my frameloaded() method at the bottom of the BODY, but not inside a function. This way it executes as late as possible during the load process. This works (i.e. it runs after the tables that have to be loaded first have been loaded) in IE and Safari, but I am having trouble with the other browsers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜