【问题标题】:Iframe SRC Value Change Not Refreshing Iframe in IE6iframe SRC 值更改不刷新 IE6 中的 iframe
【发布时间】:2010-07-01 14:23:56
【问题描述】:

我有一个包含两个 url 的数组,我使用以下方法读取并输入 iframe src 值:

document.getElementById("iframe").src = unescape(dashboard.url);

在这一行之后,我立即发出警报(document.getElementById("iframe").src),一切正常。

我的问题是,数组中的第一个 URL 似乎正确加载,并且警报显示 iframe 正在使用的正确 URL。

但是当第二个 URL 被处理并输入 iframe src 值时,警报会显示正确的 URL,但是我在同一页面上的 iframe 没有被正确的 URL 刷新,因此仍然显示我的数组中的第一个 URL 之前有效。

我是否遗漏了什么 - 这是我所看到的某种 IE6 错误,第二次没有调用 iframe。

我通过放置 onLoad="alert('Test');" 注意到了这一点在我的 iframe 中,它只出现了一次,而不是第二个 URL 的第二次。

有什么想法吗?

顺便说一句,我正在使用 setTimeout() 调用来循环遍历数组。

谢谢。

【问题讨论】:

    标签: javascript internet-explorer-6


    【解决方案1】:

    See it in action.(适用于 x 浏览器)

    <iframe id="rotator" src="http://...first"></iframe>
    
    <script>
    // start when the page is loaded
    window.onload = function() {
    
      var urls = [
        "http://...first",
        "http://...second",
        // ....
        "http://...tenth" // no ,!!
      ];
    
      var index = 1;
      var el = document.getElementById("rotator");
    
      setTimeout(function rotate() {
    
        if ( index === urls.length ) {
          index = 0;
        }
    
        el.src = urls[index];
        index  = index + 1;
    
        // continue rotating iframes
        setTimeout(rotate, 5000);
    
      }, 5000); // 5000ms = 5s
    };
    </script>
    

    【讨论】:

    • 谢谢,但真的不是我想要的答案。
    • 您好,您可以尝试使用带有“.xml”扩展名的 url 的 rotator,请让我知道它是否有效 - 谢谢。
    • 你可以试试,我贴的例子可以修改:jsbin.com/ucika/3/edit(编辑代码点击预览)
    猜你喜欢
    • 2015-07-29
    • 2014-05-02
    • 1970-01-01
    • 2013-05-21
    • 2012-04-15
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多