How to reload an IFrame every x seconds?

社会主义新天地 提交于 2019-12-13 01:17:03

问题


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

Thanks.


回答1:


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>


来源:https://stackoverflow.com/questions/4403864/how-to-reload-an-iframe-every-x-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!