views:

30

answers:

1

Hi,

I have an array of two urls that I read and feed into an iframe src value using:

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

Immediately after this line, I issue an alert(document.getElementById("iframe").src), which all works fine.

My problem is, is that the first URL in the array seems to load correctly and the alert display the correct URL being used by the iframe.

But when the second URL comes around to be processed and fed into the iframe src value, the alert displays the correct URL, but my iframe which is on the same page is not being refreshed with the correct URL and so still displays the first URL in my array that worked previously.

Am I missing something - is this an IE6 bug of some sort as from what I can see, the iframe second time around is not being called.

I noticed this by putting an onLoad="alert('Test');" in my iframe and it only appeared once and NOT the second time for the second URL.

Any ideas?

By the way, I am using a setTimeout() call to cycle through the arrays.

Thanks.

A: 

See it in action. (works x-browser)

<iframe id="rotator" src="http://...first"&gt;&lt;/iframe&gt;

<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>
galambalazs
Thanks but really not the answer I was after.
tonsils
Hi, are you able to try your rotator with urls that a have a ".xml" extension and pls let me know if it works - thanks.
tonsils
You can try it, the example I've posted can be modified: http://jsbin.com/ucika/3/edit (edit the code and click preview)
galambalazs