Need iframe to auto update
I have a situation where I need to update an iframe approximately every 30 seconds. I have looked through the forums and tried several things but 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?
+3
source to share
2 answers
Use the 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 the working example below
+1
source to share
iframe is an element, it is not a single window-like object and to change its purpose you just need to update your src attribute, document.getElementById('YOURFRAMEID').src="http://google.com/";
or something like that
Credits here Change url in iframe with javascript
+2
source to share