我如何使Iframe每5秒进入一个随机页面 [英] How Do I make an Iframe go to a random page every 5 seconds
问题描述
我需要一个iframe的帮助。
到目前为止,我已经设置了这个代码
然而,我不想要按钮。我希望iframe按照每五秒钟的网页列表顺序重定向,因为:
在它旁边,我有一个幻灯片,当它的徽标出现时,我希望帧重定向到
例子:
< blockquote>
Facebook logo> href =/ facebook
[5秒钟后]
Vite logo> href =/ vite
[5秒后]
MULTI徽标> href =/ multi
感谢堆
你可以尝试这样的事情。注意:您使用的网站必须包含正确的iframe和原始标题(或从与父网站相同的域中提供)才能显示在您的iframe中
// iframe的循环访问网站的网址= [https://wikipedia.org,https://stackoverflow.com ,https://stackoverflow.com/questions/44497495/how-do-i-make-an-iframe-go-to-a-random-page-every-5-secounds#],//可变变量iframe节点的参考帧,//以毫秒为单位显示每个网站的时间INCLUDE(){currentSlide =(currentSlide + 1)%websites.length; iframe.src = websites [currentSlide];} //等待文档loadwindow.onload = function(){//获取iframe引用iframe = document.getElementById(slides); //使用setInterval设置切换幻灯片的重复任务setInterval(switchSlides,INTERVAL)}
< iframe id =slidesheight =300pxwidth =100%name =iframe_a>< / iframe>
I need help with an iframe.
So far, I have this code set up
<iframe height="300px" width="100%" src="/vite" name="iframe_a"></iframe>
<button><a href="/multi" target="iframe_a">MULTI</a></button>
<button><a href="/facebook" target="iframe_a">Facebook</a></button>
However, I don't want the buttons. I want the iframe to redirect in order of a list of web pages every five seconds because:
Next to it, I have a slideshow, and when its logo appears, I would like the frame to redirect to the page of which the logo is indicating.
Example:
Facebook logo > href="/facebook"
[5 seconds later]
Vite logo > href="/vite"
[5 seconds later]
MULTI logo > href="/multi"
I already have the slideshow setup, just asking for the frame.
Thanks heaps
You can try something like this. Note: The websites you use must include the correct iframe and origin headers (or be served from the same domain as the parent site) to display inside your iframe
//Array of URLs for the iframe to cycle through
var websites=["https://wikipedia.org","https://stackoverflow.com","https://stackoverflow.com/questions/44497495/how-do-i-make-an-iframe-go-to-a-random-page-every-5-secounds#"],
//Variable to hold the iframe node reference
iframe,
//Time to show each website in milliseconds
INTERVAL=5000,
//Variable to keep track of currentSlide being shown
currentSlide=-1;
//Method to update the SRC attribute of iframe
function switchSlides(){
currentSlide = (currentSlide+1)%websites.length;
iframe.src = websites[currentSlide];
}
//Wait for document to load
window.onload=function(){
//Get iframe reference
iframe = document.getElementById("slides");
//Use setInterval to set up repeating task of switching slides
setInterval(switchSlides,INTERVAL)
}
<iframe id="slides" height="300px" width="100%" name="iframe_a"></iframe>
这篇关于我如何使Iframe每5秒进入一个随机页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!