2013-08-21 31 views
7

后,我已经一个iframe放置在我的网页的身体是这样的:负载指示停留在Firefox中的iframe完加载

<iframe src="about:blank" onload="this.contentWindow.document.write('some text')"> 

它的作品不够好,onload事件取代iframe的内容与“一些文本”和完蛋了。

但在Firefox中,它会导致旋转轮“加载指示器”,它向您显示页面正在加载到永不消失。只有文本被插入到iframe中,所以没有其他内容在等待被加载。当我从页面中删除iframe时,它会消除这个问题,所以我知道,这是导致它的iframe。

它在IE和Chrome中正常工作。现在

,我可以做这样的事情:

<iframe src="about:blank" onload="this.contentWindow.document.write('some text'); t.contentWindow.stop();"> 

这在Firefox中解决了这个问题,但它可以防止任何图像在iframe加载(我不使用任何在本例中插入文本,但稍后会添加它们)。

那么,我该如何解决这个问题呢?

回答

1

为什么通过首先使用同一个iframe的load事件触发写入contentWindow?

另一种方法只是创建一个iframe并将一些内容加载到它的图像 - 按预期在Firefox上工作。没什么大不了。

<!DOCTYPE html> 
<html> 
<head> 
<script type="text/javascript"> 
function createIframe(){ 
    var f = document.getElementsByTagName('body') [0].appendChild(document.createElement('iframe')); 
    f.contentWindow.document.write('<img src="http://www.funimage.org/uploads/posts/2013-02/1361892989_1_14.jpg" />'); 
} 
</script> 
</head> 
<body onload="createIframe()"> 

</body> 
</html> 
13

请确保您调用this.contentWindow.document.close();在写入iframe之后。

+1

另一个答案不适用于我,而这一个。干杯! – Campbeln

+1

这个伎俩! –