IE6中的iframe SRC值更改未刷新Iframe

时间:2010-07-01 14:23:56

标签: javascript internet-explorer-6

我有一个由两个网址组成的数组,我使用以下内容读取并输入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()调用来遍历数组。

感谢。

1 个答案:

答案 0 :(得分:0)

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>
相关问题