在iframe中旋转网址 [英] Rotating URLs within an Iframe
本文介绍了在iframe中旋转网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有10个不同的网址,我想要输入iframe src属性,我也想旋转说iframe中所有10个网址之间每隔5秒。
I have 10 different urls that I want to feed into an iframe src attribute that I would also like to rotate say every 5 seconds between all the 10 urls within the iframe.
不确定如何使用javascript / best方法执行此操作?
Unsure how to do this using javascript/best approach?
对不起,应该提到我使用的是IE6。
Sorry, should've mentioned that I am using IE6.
谢谢。
推荐答案
<iframe id="rotator" src="http://...first"></iframe>
<script>
// start when the page is loaded
window.onload = function() {
var urls = [
"http://...first",
"http://...second",
// ....
"http://...tenth" // no ,!!
];
var index = 1;
var el = document.getElementById("rotator");
setTimeout(function rotate() {
if ( index === urls.length ) {
index = 0;
}
el.src = urls[index];
index = index + 1;
// continue rotating iframes
setTimeout(rotate, 5000);
}, 5000); // 5000ms = 5s
};
</script>
这篇关于在iframe中旋转网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文