2015-04-12 71 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);