如何在php页面中刷新iframe

how to refresh an iframe in php page

本文关键字:刷新 iframe php      更新时间:2023-09-26

可能重复:
如何自动刷新iframe

我需要从源代码刷新php页面上的iframe,这是提供的

src = "<?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>

演示:http://jsfiddle.net/GqvZS/3/

如果您正在寻找一种不启用javascript的方法,并且有权修改iframe HTML,那么您可以将此重载代码添加到iframe HTML:的<head>标记中

<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 http-equiv="refresh" content="1" />