2015-04-12 72 views
0

我用下面的代碼來創建一個iframe:iframe的內容在IE中獲取html是未定義的?

Ifrm = document.createElement("IFRAME"); 
document.body.appendChild(Ifrm); 
IfrmBod = $(Ifrm).contents().find('body'); 
IfrmBod.append('<p>Test</p>'); 

追加jQuery函數不正確,即工作的這個例子。 最後 當我使用IfrmBod.html()時,它在Chrome中正常工作,但在IE中不起作用。在IE IfrmBod.html()未定義。

+0

它在其他瀏覽器中工作正常嗎? –

+0

http://stackoverflow.com/questions/9527582/write-some-html-and-js-to-a-iframe-not-working-in-ie-is-not-defined –

+3

請不要大寫每個單詞一句話。這是非常刺激閱讀 – mplungjan

回答

0

我已經通過settimeout解決了這個問題。

有沒有更好的方法?

Ifrm = document.createElement("IFRAME"); 
Ifrm.style.width = "100%"; 
Ifrm.style.height ="100%"; 
document.body.appendChild(Ifrm); 
setTimeout(function(){ 
IfrmBod = $(Ifrm).contents().find('body'); 
... 
},50);