Javascript:错误'对象必需'.我无法破译它.你能?

Jan*_*nis 2 javascript debugging flir

我在我的一个网站上使用了一个名为"Facelift 1.2"的javascript,虽然该脚本适用于Safari 3,4b和Opera,OmniWeb和Firefox,但它并不适用于任何IE版本.但即使在工作浏览器中我得到以下错误我无法破译.

也许在适当的时候 - 有更多的经验Javascript - 我将能够,但现在我想我会问你们中的一些人,在这里.

以下是我在IETester中测试Interet Explorer 6,7和8的页面时出现的错误弹出: IE错误弹出http://img21.imageshack.us/img21/3651/err2.png

以下内容来自Firefox 3.0.6中的Firebug控制台: Firebug控制台日志http://img100.imageshack.us/img100/3636/err3.png

该网站是:http://www.457cc.co.nz/index.php如果它可以帮助您看到行动中提到的问题.

我还查找了第620行对应的内容: "第76行"是:

this.isCraptastic = (typeof document.body.style.maxHeight=='undefined');
Run Code Online (Sandbox Code Playgroud)

这是代码块的一部分(取自flir.js):

// either (options Object, fstyle FLIRStyle Object) or (fstyle FLIRStyle Object)
,init: function(options, fstyle) { // or options for flir style
    if(this.isFStyle(options)) { // (fstyle FLIRStyle Object)
        this.defaultStyle = options;
    }else { // [options Object, fstyle FLIRStyle Object]
        if(typeof options != 'undefined')
            this.loadOptions(options);

        if(typeof fstyle == 'undefined') {
            this.defaultStyle = new FLIRStyle();
        }else {
            if(this.isFStyle(fstyle))
                this.defaultStyle = fstyle;
            else
                this.defaultStyle = new FLIRStyle(fstyle);
        }
    }

    this.calcDPI();

    if(this.options.findEmbededFonts)
        this.discoverEmbededFonts();

    this.isIE = (navigator.userAgent.toLowerCase().indexOf('msie')>-1 && navigator.userAgent.toLowerCase().indexOf('opera')<0);
    this.isCraptastic = (typeof document.body.style.maxHeight=='undefined');

    if(this.isIE) {
        this.flirIERepObj = [];
        this.flirIEHovEls = [];
        this.flirIEHovStyles = [];    
    }
}
Run Code Online (Sandbox Code Playgroud)

整个脚本也可以在我的服务器上找到:http://www.457cc.co.nz/facelift-1.2/flir.js

我只是不知道从哪里开始寻找错误,特别是因为它只影响IE,但在其余部分工作.也许你们有个主意.我很乐意听到他们.

谢谢阅读.Jannis

PS:这是Opera的错误控制台报告:

JavaScript - http://www.457cc.co.nz/index.php
Inline script thread
Error:
name: TypeError
message: Statement on line 620: Cannot convert undefined or null to Object
Backtrace:
  Line 620 of linked script http://www.457cc.co.nz/facelift-1.2/flir.js
                    document.body.appendChild(test);
  Line 70 of linked script http://www.457cc.co.nz/facelift-1.2/flir.js
            this.calcDPI();
  Line 2 of inline#1 script in http://www.457cc.co.nz/index.php
            FLIR.init();
stacktrace: n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
Run Code Online (Sandbox Code Playgroud)

Tri*_*ych 7

我同意tvanfosson - 你之所以得到这个错误的原因很可能是因为你在init()页面加载之前调用了,所以document.body还没有定义.

在您链接的页面中,您应将以下代码移到页面底部(就在关闭html标记之前:

<script type="text/javascript">
    FLIR.init({ path: 'http://www.457cc.co.nz/facelift-1.2/' });
    FLIR.auto();
</script>
Run Code Online (Sandbox Code Playgroud)

更好的是,您应该将初始化附加到文档的ready事件中.如果你这样做,你甚至不需要将你的javascript移动到文件的底部.使用jquery:

$(document).ready( function(){
    FLIR.init({ path: 'http://www.457cc.co.nz/facelift-1.2/' });
    FLIR.auto();
});
Run Code Online (Sandbox Code Playgroud)

更多关于jquery的document.ready事件»