Skip to content Skip to sidebar Skip to footer

Trying To Display A Random Video On Page Load

I am trying to load a random video on page load. This is some javascript that I threw together that I thought might work. I'm not that familiar with javascript, so there might be a

Solution 1:

Would be more generalizable and easier to add more videos if you use an Array:

var videos = [
    'Ig-DbfPoz3o',
    'estPhyfBGho',
    '6JL4hpnZklk'
];

var index=Math.floor(Math.random() * videos.length);
var html='<div class="span4"><h3 class="meet">Meet the Makers</h3><iframe width="100%" height="200" src="http://www.youtube.com/embed/' + videos[index] + '" frameborder="0" allowfullscreen></iframe></div>';
document.write(html);

Post a Comment for "Trying To Display A Random Video On Page Load"