0

for domload performance im reaching to load my 2 ytb iframes through a loop after Onload, it works for the first one, console is not throwing errors, target divs are the 2 <div class="ytb-holder-image"></div>, am i missing something?

var srcs= new Array();
    srcs[0]= "fhIHMDpbQDI";
    srcs[1]= "oMRZp7cp79g";

function createIframe(){

    for (var j = 0; j < 1; j++)
    {
      var i = document.createElement("iframe");
          i.src = 'http://www.youtube.com/embed/'+srcs[j];
          i.width = "853xp";
          i.height = "480px";
          document.getElementsByClassName("ytb-holder-image")[j].appendChild(i);
        };

    }

for documentation, if someone wants to load his content in a similar way here are the conditions for IE:

if (window.addEventListener)
window.addEventListener("load", createIframe, false);
else if (window.attachEvent)
window.attachEvent("onload", createIframe);
else window.onload = createIframe;
thegrunt
  • 1,054
  • 1
  • 11
  • 22
  • probably a better approach; http://stackoverflow.com/questions/1290131/javascript-how-to-create-an-array-of-object-literals-in-a-loop – thegrunt Feb 06 '13 at 17:12
  • with the new embed Youtube API: https://developers.google.com/youtube/iframe_api_reference?hl=de – thegrunt Feb 06 '13 at 17:12

0 Answers0