可能重複:
how to refresh an iframe automatically如何刷新在PHP頁面的iframe
我需要從它的來源,這是由
給出刷新PHP頁面的iframesrc = "<?php echo site_url();?>/information"
我希望經常這樣做,比方說每隔1秒或2秒。
尋找一種在JavaScript中執行此操作的方法,我可以搜索iframe的id並刷新它。
可能重複:
how to refresh an iframe automatically如何刷新在PHP頁面的iframe
我需要從它的來源,這是由
給出刷新PHP頁面的iframesrc = "<?php echo site_url();?>/information"
我希望經常這樣做,比方說每隔1秒或2秒。
尋找一種在JavaScript中執行此操作的方法,我可以搜索iframe的id並刷新它。
<script type="text/javascript">
var timer;
function refreshIframe(){
if(timer)
clearInterval(timer)
timer = setTimeout(refreshIframe,5000)
var iframe = document.getElementById('iframe');
iframe.src='http://google.com';
}
refreshIframe();
</script>
<iframe id="iframe" src="http://google.com" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
如果您正在尋找這樣做未啓用JavaScript的方式,並有機會獲得修改的iframe HTML,那麼你可以加入這個重載代碼爲<head>
標籤的iframe HTML的:
<meta http-equiv="refresh" content="600">
的Javascript方式:
setInterval(refreshIframe,1000);
function refreshIframe() {
window.frames["myframe"].src = window.frame["myframe"].src;
}
<iframe src="/information" name='myframe' id='myframe'></iframe>
Meta標記方式:
<meta http-equiv="refresh" content="1" />
php不能幫助這裏。代表 – RiaD
爲什麼你問同樣的問題2次? –