2009-02-26 104 views
2

我在我的一個網站中使用了一個名爲'Facelift 1.2'的javascript,而這個腳本在Safari 3,4b和Opera,OmniWeb和Firefox中的工作原理並沒有在任何IE版本中使用。 但即使在工作瀏覽器中,我收到以下錯誤,我無法解密。Javascript:錯誤'Object Required'。我無法破譯它。你可以嗎?

也許在適當的時間 - 在事情上有更多的經驗Javascript-I將能夠,但現在我想我會問你們中的一些人,在這裏。

以下是錯誤彈出我IETester得到測試頁Interet資源管理器6,7和8: IE Error Pop Up http://img21.imageshack.us/img21/3651/err2.png

以下是Firebug控制檯在Firefox 3.0.6: Firebug Console Log 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'); 

這是代碼(從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 = [];  
    } 
} 

整個腳本也可在我的服務器上: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' 

回答

7

我同意tvanfosson - 你得到這個錯誤的原因很可能是因爲你調用init()之前完成頁面加載,所以document.body還沒有定義。

在你的鏈接頁面,你應該將下面的代碼移動到頁面(剛剛閉幕的HTML標記之前的底部:

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

更妙的是,你應該初始化附加到文件的ready事件如果你這樣做,你甚至不需要將你的javascript移動到文件底部。使用jQuery:

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

More on jquery's document.ready event »

0

編輯離開上下文解答。請參閱@三聯的(接受的)正確答案的答案。

我的建議是將JavaScript的包含到您的標記結束。我認爲發生的事情是代碼在DOM完全加載之前執行,因此當您嘗試引用它來確定maxHeight樣式屬性時,document.body爲null。將javascript包含到標記末尾應足以保證文檔正文至少被加載並避免出現此特定錯誤。

... rest of html.... 

    <script type='text/javascript' 
      src='http://www.457cc.co.nz/facelift/flir.js'> 
    </script> 
</body> 
</html> 
+0

差不多。包含該文件實際上並不訪問DOM。他在頁面中有一個腳本塊,它實際運行導致答案的init腳本。看到我的答案。 – Triptych 2009-02-26 21:21:29

+0

感謝您的回答我不認爲我會想到它與頁面加載的任何時候都有關係。 – Jannis 2009-02-26 21:26:04

0

安裝.NET Framework v2和解決問題。

相關問題