【问题标题】:How to reload an IFrame every x seconds?如何每 x 秒重新加载一个 IFrame?
【发布时间】:2011-05-23 04:15:14
【问题描述】:

想知道如何每隔 x 秒重新加载一个 iframe,最好不要使用 javascript。

谢谢。

【问题讨论】:

    标签: javascript html iframe refresh reload


    【解决方案1】:

    带有Refresh: x HTTP 标头或带有加载到 iframe 的文档中的 HTML 元素:

    <meta http-equiv="refresh" content="x" />
    

    此元素应放置在文档的&lt;head/&gt; 元素内。

    如果您无法控制加载到框架中的文档或提供该文档的服务器,您有两种选择:

    1. JavaScript。
    2. 使用上述&lt;meta/&gt; 元素编写另一个HTML 页面,并在该页面中包含一个指向另一个页面的iframe。因此,您将在 iframe 中拥有一个 iframe:外部文档 -> iframe(具有元刷新的内部文档)-> iframe(原始 iframe 目标)

    编辑:关于选项 #2,这是 PHP 中一个不错的通用 iframe,它在刷新时间和样式方面提供了一些灵活性。只需用类似这样的方式调用它:

    http://www.mydomain.com/genericIframe.php?url=http://my.domain.com/mypage.htm&amp;refreshTime=60&amp;style=putYourStyleAttribHere

    这是 PHP/HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Generic Iframe</title>
        <meta http-equiv="refresh" content="<?php print $_REQUEST['refreshTime']; ?>" />
    </head>
    <body>
        <iframe src="<?php print $_REQUEST['url']; ?>" style="<?php print $_REQUEST['style']; ?>"></iframe>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 2012-03-24
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多