Javascript正在重新加载iframe

时间:2015-04-29 15:00:12

标签: javascript html iframe

嗨,任何人都可以帮助我在这里我有这个代码可以很好地重新加载一个iframe ID但我似乎无法让它与一个类工作,因为我希望它重新加载超过1 iframe或失败多于1 iframe标识。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
<head>
<title>Javascript IFrame Reload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"><!--
// set your interval in milliseconds
var reloadInterval = 3000;
// this will run when the document is fully loaded
function init() {
 setTimeout('reload()',reloadInterval);
}
// this reloads the iframe, and triggers the next reload interval
function reload() {
 var iframe = document.getElementById('reloader');
 if (!iframe) return false;
 iframe.src = iframe.src;
 setTimeout('reload()',reloadInterval);
}
// load the init() function when the page is fully loaded
window.onload = init;
--></script>
</head>
<body>
<iframe id="reloader" width="500" height="400" src="http://www.google.com/"/>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

快速更新我终于实现了我的目标。每5秒自动重新加载页面上的1个iframe。

如果有人有兴趣https://jsfiddle.net/

相关问题