I have an iframe that I wanna update every 20 seconds. So basically, the url of the iframe should change to a new one from the array and it refreshes, every 20 seconds but my code doesn’t seem to work.
var Uni = {
init: function () {
this.refresh();
},
refresh: function () {
var urlArr = [
'http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/',
'http://stephendnicholas.com/archives/310',
'http://msdn.microsoft.com/en-us/scriptjunkie/ff696765',
'http://www.jquery4u.com/jquery-functions/jquery-each-examples/'
],
iframeSrc = document.querySelector('#uni iframe').src;
for (var i = 0, max = urlArr.length; i < max; i++) {
setInterval(function(){
iframeSrc = urlArr[i];
}, 20000);
}
}
}
Uni.init();
HTML:
<body id="uni">
<iframe src="http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/">
You browser doesn't support iframes, please update it.
</iframe>
</body>
Please help.
Check the last line of yoururlArr[]declaration:Thanks to @AndyE for the hint.
Update: Solution + working fiddle