Skip to content Skip to sidebar Skip to footer

How Do I Make An Iframe Go To A Random Page Every 5 Seconds

I need help with an iframe. So far, I have this code set up However, I don't want the buttons. I want the iframe to redirect in order of a list of web pages every five seconds be

Solution 1:

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 throughvar 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 millisecondsINTERVAL=5000, 
//Variable to keep track of currentSlide being shown
currentSlide=-1;

//Method to update the SRC attribute of iframefunctionswitchSlides(){
  currentSlide = (currentSlide+1)%websites.length;
  iframe.src = websites[currentSlide];
}

//Wait for document to loadwindow.onload=function(){
  //Get iframe reference
  iframe = document.getElementById("slides");
  //Use setInterval to set up repeating task of switching slidessetInterval(switchSlides,INTERVAL)
}
<iframeid="slides"height="300px"width="100%"name="iframe_a"></iframe>

Post a Comment for "How Do I Make An Iframe Go To A Random Page Every 5 Seconds"