vendredi 24 juin 2016

Randomly Load URL From List Into IFrame Every X Seconds

I'm currently using the below code - which is exactly what I want - bar one thing, I'd like it to randomly select a url as appose to it's current sequential action…

Any tips on how to achieve this will be super greatly appreciated…

    // start when the page is loaded
window.onload = function() {

  var urls = [
    "http://url.club/one",
    "http://url.club/two",
    "http://url.club/three"
  ];

  var index = 1;
  var el = document.getElementById("raves");

  setTimeout(function rotate() {

    if ( index === urls.length ) {
      index = 0;
    }

    el.src = urls[index];
    index  = index + 1;

    // continue rotating iframes
    setTimeout(rotate, 5000);

  }, 5000); 
};




Aucun commentaire:

Enregistrer un commentaire