【问题标题】:Loading indicator stays in Firefox after iframe finished loadingiframe 完成加载后,加载指示器停留在 Firefox 中
【发布时间】:2013-08-21 09:08:53
【问题描述】:

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

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

【问题讨论】:

    标签: javascript html firefox load


    【解决方案1】:

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

    【讨论】:

    • 另一个答案对我不起作用,而这个答案对我有用。干杯!
    • 多么美妙的解决方案!
    【解决方案2】:

    你为什么首先使用同一个 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多