Javascript page rotation/refresh

javascript

How can i get javascript to take a list of URL's, and refresh an iframe with the next URL on the list after a given number of seconds, in this case 45 seconds.

The list is named list.txt (one full URL per line), and the id of the iframe is #window.

Best Answer

Well I'm not going to do your work for you (though inevitably someone here will if you wait long enough) but you need to:

A). Read in the file (it would help enormously if this was a JSON file, but c'est la vie). this will depend on the file being in your domain and making an AJAX request to get it. This is hardly ideal, but if that's your setup so be it.

B). Parse the file into an array of URLs

C). Create a variable N to store an index pointer for the array and a function which reads the URL at position N sets the iframe.src to that value and then increments N

D). Execute the setInterval method for your function with a timer of 45000 (i.e. 45 seconds)