2012-07-25 16 views
1

我的應用程序在彈出窗口中有一個ajax樣式的表單。我使用一個帶有目標iframe的表單,然後在iframe.load()函數中,我取出內容並將它們顯示回我的彈出窗口中。異步窗體瓦特/ iframe目標 - OnLoad在FF,Chrome,IE9中工作,不會在IE7中得到響應

這適用於IE9,Chrome瀏覽器,火狐瀏覽器:

$("iframe[name=addpart-iframe]").load(function() { 
      //FF and IE fire the load when the popup first load, chrome does not. This kips the first onload where no submit has happened yet 
       if (firstLoad == true) { 
        firstLoad = false; 
        return; 
       } 


       var response = this.contentDocument.body.innerHTML; 
       $("#AddForm").html(response); 


      });  

這個偉大的工程,除了在IE7。當我看着this.contentDocument.body時 - 調試器說這個body不是一個有效的屬性。我查看外部HTML,並且此時我的iframe也是空的。不知道爲什麼!

回答

2

contentDocument屬性是指iframe中的文檔元素(這等同於contentWindow.document),但不是由IE8以前版本的Internet Explorer支持。

對於8之前的早期版本的IE,可以使用contentWindow屬性。

var response; 

if (this.contentDocument) { 
    response = this.contentDocument.body.innerHTML; 
} else { 
    response = this.contentWindow.document.body.innerHTML; 
} 
+0

謝謝。這最終導致了比我想象的更多的問題。原來我的iframe resposne沒有正確的 ..等等。在chrome,ff等中沒有問題,因爲響應從來沒有作爲獨立頁面呈現,但是當我這樣做時,IE將barfed並將所有內容扔到了我的iframe的中。修正了我的響應的文檔格式,最後使用$(「iframe」)。find(「」)而不是。雖然謝謝! – Yablargo 2012-07-25 16:34:40

+0

@Yablargo歡迎您。 – undefined 2012-07-25 17:15:17

相關問題