Reputation: 73
I have a situation where I need to refresh an iframe about every 30 seconds. I have looked through the forums and tried a few things, to no avail.
<iframe id="Doyle" src="http://www.dot.ca.gov/dist2/rwis/sm_doyle.php"
width="375" height="560">
</iframe>
<script>
window.setInterval("reloadIFrame();", 3000);
function reloadIFrame() {
document.frames["Doyle"].location.reload();
}
</script>
Any suggestions on how to make this work?
Upvotes: 3
Views: 4969
Reputation: 1643
Use following code
<iframe id="Doyle" src="http://www.dot.ca.gov/dist2/rwis/sm_doyle.php"
width="375" height="560">
</iframe>
<script>
window.setInterval("reloadIFrame();", 30000);
function reloadIFrame() {
var frameHolder=document.getElementById('Doyle');
frameHolder.src="http://www.dot.ca.gov/dist2/rwis/sm_doyle.php"
}
</script>
check working example below
http://plnkr.co/edit/Mre0AgMjh5o7wXl5YvVP?p=preview
Upvotes: 2
Reputation: 736
an iframe is an element, it is not an object like the window one, and to change its target you just need to update its src attribute, document.getElementById('YOURFRAMEID').src="http://google.com/";
or something like that
Credits here Change URL in an iframe using javascript
Upvotes: 2