iframe加载完成后,加载指示器将保持在Firefox中

Loading indicator stays in Firefox after iframe finished loading

本文关键字:加载 Firefox 指示器 iframe      更新时间:2023-09-26

我在页面正文中放置了一个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中的任何图像加载(我在示例插入文本中没有使用任何图像,但稍后会添加它们)。

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

确保调用this.contentWindow.docent.close();写信给iframe之后。

为什么首先使用同一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>
相关文章: