想知道如何每 x 秒重新加载一个 iframe,最好不要使用 javascript。
谢谢。
最佳答案
用Refresh: x
将文档中的 HTTP header 或 HTML 元素加载到 iframe 中:
<meta http-equiv="refresh" content="x" />
此元素应放在文档的 <head/>
内元素。
如果您无法控制加载到框架中的文档或提供它的服务器,您有两个选择:
- JavaScript。
- 用上面的
<meta/>
编写另一个 HTML 页面元素并在该页面中包含一个针对其他页面的 iframe。所以你将在 iframe 中有一个 iframe:外部文档 -> iframe(带元刷新的内部文档) -> iframe(原始 iframe 目标)
编辑:关于选项 #2,这里有一个不错的 PHP 通用 iframe,它在刷新时间和样式方面提供了一些灵 active 。只需用类似的方式调用它:
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//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>
关于javascript - 如何每 x 秒重新加载一个 IFrame?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4403864/