Variable Youtube
Written on 05/09/20 at 03:54:43 EST by GabbyGirl
JavascriptingIm trying to load a variable for five you tube videos to randomly grab one as a variable and display it on pageload


code:
<script>
   var vtube=new Array()
   vtube[0]='UT000008'
   vtube[1]='UT000008'
   vtube[2]='UT000008'
   vtube[3]='UT000008'
   vtube[4]='UT000008'
   var whichvtube=Math.floor(Math.random()*(vtube.length))
   var vtubeselected=(vtube[whichvtube])
</script>
<!--I use javascript to assign the videos into an array then select one randomly. I then attempt to pass the variable of the random selected video in the iframe -->

<iframe width="280" height="210" src="http://www.youtube.com/embed/+vtubeselected?rel=0" frameborder="0" allowfullscreen></iframe>


Comments on this article:
 
 You Tube Randomizer
Written on 05/09/20 at 03:58:24 EST by admin
[code]<script type="text/javascript">
var vtube = ['UT000008', 'UT000008', 'UT000008', 'UT000008', 'UT000008'];
var whichvtube = Math.floor(Math.random()*(vtube.length));
var vtubeselected = vtube[whichvtube];

document.write('<iframe width="280" height="210" src="http://www.youtube.com/embed/' + vtubeselected + '?rel=0" frameborder="0" allowfullscreen></iframe>');
</script>[code]

 using jQuery
Written on 05/09/20 at 04:00:05 EST by GabbyGirl
using jQuery: try this one. (iframe is the id of the iframe tag)


code:
$(document).ready(function(){
$('#iframe').src='http://www.youtube.com/embed/+vtubeselected?rel=0'+<whatever no want to add>
});


News and Comments Brought to you by: Geeks and Bloggers
The comments are owned by the poster. We aren't responsible for its content.