开发者

Javascript: window.onload problem

This isn't working in IE (although it does work in FFX). Why?

Using HTML in the header:

<script type="application/javascript">

    // And finally, let's call the code ourselves.
    window.onload = lbp.init;

</script>

And then the script:

// lbp is the script's universal va开发者_JS百科riable, which retains everything
var lbp = {};

// The sequence of functions to trigger
lbp.init = function() {
    alert('hi');
}

Thanks in advance for your help =)


I don't know if IE supports application/javascript. Did you try text/javascript?

Also: is lbp initialized before setting window.onload?


IE does not support application mime types except for with PDFs. This means IE will completely ignore your JavaScript. Change it to mime type text/javascript.


I think you have declared lbp after window.onload = lbp.init; code. Your code is not working because of the sequence issue.

Try the code in the following sequence.

<script type="text/javascript" language="javascript">
    var lbp = {};
        // The sequence of functions to trigger
        lbp.init = function() {
        alert('hi');
    }
        
    // And finally, let's call the code ourselves.
    window.onload = lbp.init;
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜