php - 如何在每5秒后更改iframe不同的src [英] php - how to change iframe different src after every 5 second
本文介绍了php - 如何在每5秒后更改iframe不同的src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过以下代码,但可能会在点击时更改,我想在每隔5秒钟后更改iframe内部部分。
i have tried following code but it could change on click, i want to change the iframe inner part after every 5 second interval.
<html>
<body>
<iframe id="foo"></iframe>
<a href="http://www.mydomain.com" target="foo">This page</a>
</body>
</html>
基本上我的想法就是我会在iframe里面显示这些页面,这5个网页会在之后发生变化每隔5秒钟后另一次。
basically idea is that i have pages which will display inside of iframe, these 5 web pages will change after another after every 5 second interval.
谢谢
推荐答案
基于@Matthew Dean回答:
Based on @Matthew Dean answer :
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fouad Ali</title>
<script>
var links = ["http://www.example.com/page","http://www.example.com/anotherpage"];
var i = 0;
var renew = setInterval(function(){
document.getElementById("foo").src = links[i];
if(links.length == i){
i = 0;
}
else i++;
},5000);
</script>
</head>
<body>
<iframe id="foo" src="http://example.com"></iframe>
</body>
</html>
重要提示:并非所有网站都可以在iframe中使用。确保您放在链接
数组中的网站允许在iframe中使用。
Important: Not all sites can be used within iframes. Be sure that the website you put in the links
array allows to be used inside an iframe.
这篇关于php - 如何在每5秒后更改iframe不同的src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文