简体   繁体   English

Javascript:window.onload 问题

[英]Javascript: window.onload problem

This isn't working in IE (although it does work in FFX).这在 IE 中不起作用(尽管它在 FFX 中有效)。 Why?为什么?

Using HTML in the header:在标题中使用 HTML:

<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 variable, 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 .我不知道 IE 是否支持application/javascript Did you try text/javascript ?你试过text/javascript吗?

Also: is lbp initialized before setting window.onload ?另外:在lbp设置初始化之前window.onload

I think you have declared lbp after window.onload = lbp.init;我想你已经宣布lbpwindow.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>

IE does not support application mime types except for with PDFs. IE 不支持除 PDF 之外的应用程序 mime 类型。 This means IE will completely ignore your JavaScript.这意味着 IE 将完全忽略您的 JavaScript。 Change it to mime type text/javascript .将其更改为 mime 类型text/javascript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM