I’m trying to change the src of an iframe every 2 seconds with different page but I failed miserably so far. Can anyone tell me what’s wrong with this code? It only loads the last file, 5.html and not the other ones, 1.html 2.html 3.html and 4.html
function reloadiframe(nbr) {
setTimeout(function () {
document.getElementById("iframe").src = nbr + ".html";
}, 2000);
}
function reload() {
for (i=1;i<=5;i++) {
reloadiframe(i);
}
}
setTimeoutdoes not wait. The timeouts all fire at pretty much exactly the same time, since they are all started at pretty much exactly the same time. Just a small change will fix the problem: