use*_*305 8 html javascript firefox load
我有一个iframe放在我的页面的主体中,如下所示:
<iframe src="about:blank" onload="this.contentWindow.document.write('some text')">
Run Code Online (Sandbox Code Playgroud)
它工作得很好,onload事件用"some text"替换iframe的内容就是这样.
但是在Firefox中它会导致旋转轮"加载指示器",它会向您显示正在加载的页面永远不会消失.只有文本插入到iframe中,因此没有其他内容挂起,等待加载.当我从页面中删除iframe时,它会删除问题,所以我知道,这就是导致它的iframe.
它在IE和Chrome中正常运行.
现在,我可以这样做:
<iframe src="about:blank" onload="this.contentWindow.document.write('some text'); t.contentWindow.stop();">
Run Code Online (Sandbox Code Playgroud)
这解决了Firefox中的问题,但它阻止了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>
Run Code Online (Sandbox Code Playgroud)