简体   繁体   English

如何使iframe每5秒转到随机页面

[英]How Do I make an Iframe go to a random page every 5 seconds

I need help with an iframe. 我需要有关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: 我希望iframe每五秒钟按网页列表的顺序进行重定向,因为:
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" Facebook徽标> href =“ / facebook”
[5 seconds later] [5秒后]
Vite logo > href="/vite" Vite徽标> href =“ / vite”
[5 seconds later] [5秒后]
MULTI logo > href="/multi" MULTI徽标> 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 注意:您使用的网站必须包含正确的iframe和原始标头(或从与父网站相同的域提供)才能显示在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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM