问题
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:
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.
来源:https://stackoverflow.com/questions/8872126/how-to-refresh-an-iframe-not-using-javascript