如何每x秒重新加载一个IFrame? [英] How to reload an IFrame every x seconds?

查看:124
本文介绍了如何每x秒重新加载一个IFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



谢谢。

解决方案

刷新:x HTTP标头或文档中的HTML元素加载到iframe中:

 << ; meta http-equiv =refreshcontent =x/> 

这个元素应该放在文档的< head /> 元素



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


  1. JavaScript。

  2. 使用上面的< ; meta /> 元素,并在该页面中包含一个定位到其他页面的iframe。因此,您将在iframe中包含一个iframe:外部文档 - > iframe(带有元刷新的内部文档) - > iframe(原始iframe目标)


    编辑:关于选项#2,这是PHP中一个体面的通用iframe,它在刷新时间和样式方面提供了一些灵活性。只需使用以下内容调用它即可:



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



    这里是PHP / HTML:

     <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://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 =refreshcontent =<?php print $ _REQUEST ['refreshTime'];?> />
    < / head>
    < body>
    < iframe src =<?php print $ _REQUEST ['url'];?> style =<?php print $ _REQUEST ['style'];?>>< / iframe>
    < / body>
    < / html>


    Was wondering how I can reload an iframe every x seconds, perferably not using javascript.

    Thanks.

    解决方案

    With a Refresh: x HTTP header or with an HTML element in the document loaded into the iframe:

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

    This element should be placed inside of the document's <head/> element.

    If you do not have control over the document loaded into the frame or the server that it is served from, you have two options:

    1. JavaScript.
    2. Write another HTML page with the above <meta/> element and include an iframe in that page targeting the other page. So you will have an iframe inside an iframe: outer document -> iframe(inner document with meta-refresh) -> iframe(original iframe target)

    EDIT: Regarding option #2, here's a decent generic iframe in PHP that gives some flexibility in terms of refresh time and style. Just call it with something like:

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

    Here's the 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>
    

    这篇关于如何每x秒重新加载一个IFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆