Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  144] [ 5]  / answers: 1 / hits: 15954  / 11 Years ago, fri, march 22, 2013, 12:00:00

I have the following JavaScript to rotate pages in a iframe tag every 5 seconds.



function setPage() {
if (i == pages.length) {
i = 0;
}
alert(pages[i]); //verify the right url is there
var elmnt = document.getElementById('dashboard');
elmnt.setAttribute('src', pages[i]);

i++;
}
setInterval(setPage(), 5000);


The loop, interval, etc., is working. However, nothing changes for the src attribute of my iframe tag.



I tested with both IE8 and Chrome.



What am I doing wrong? How can I accomplish that (no jQuery...)


More From » javascript

 Answers
14

I'd suggest you to use elmnt.src = pages[i] instead.



If it still gives you error, then most probably you are trying to target element, that doesn't have src property. Check that elemt.tagName gives you IFRAME.


[#79422] Thursday, March 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamronr

Total Points: 749
Total Questions: 110
Total Answers: 122

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
kamronr questions
Mon, Dec 21, 20, 00:00, 3 Years ago
Fri, Oct 16, 20, 00:00, 4 Years ago
Sat, Oct 3, 20, 00:00, 4 Years ago
Sun, Jul 28, 19, 00:00, 5 Years ago
;