I have an iframe which I would like to refresh every fifteen seconds, but I'm not sure how to do this or if it is even possible. If it is, how would I go about doing this without the use of JavaScript. If JavaScript is necessary then please post how I would do it in JavaScript. Thank you.
1 Answer
You might be able to achieve this using a meta tag, inside the HEAD element of the HTML file being included inside the iframe:
<meta http-equiv="refresh" content="5" />
This will refresh the page every 5 seconds. See the Wikipedia entry.
However, using JavaScript, this is the way to go:
function reloadIframe() {
var iframe = document.getElementById('my-iframe');
iframe.src = "http://some/url/";
setTimeout("reloadIframe()", 5000);
}
window.onload = reloadIframe;
This will reload the iframe with ID my-iframe every five seconds, by pointing it to http://some/url.
13 Comments
Twister
That will probably work, but is there any way to specifically just refresh the iframe?
Milad Naseri
Wouldn't that just refresh the iframe if the meta tag was in the head part of the page inside the iframe?
Milad Naseri
Other than that, you have no way of executing time-based events without using JavaScript.
Dima Pasko
What is the page inside your iframe? Could you add this meta-tag to this page.
Milad Naseri
That is exactly what I'm trying to accomplish here. If you can edit that page, that page also has a root HTML element, inside which must be a HEAD element (if not, you can add one yourself). This meta tag goes there.
|