How to make videos random on blogs and websites by Javascript Reviewed by Kampung Tangguh Semeru dan 17 Orang Lainnya on Rating: 4

How to make videos random on blogs and websites by Javascript

Ok my friends, Now I will give a tutorial how can we show random or random video on your blog or website. For example, my friends just look at this blog, under the header there is a video that I show from youtube.com random. It is very easy guys, we only use javascript to do that, the script used the array in javascript. Here is the code or steps comrades.
The steps are:

1. Add a widget in our blogger or friends just added templates, exactly between <body> and </ body>

2. Paste the following script colleagues (this script is placed when adding a widget, not between tags <body>),


<script language='JavaScript'>
                videos = new Array(8);
                videos[0] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/MiyFkIGSvhA' width='520'/>&quot;;
                videos[1] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/3wHUyvi0rw0' width='520'/>&quot;;
                videos[2] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/jjpOcYZTpQ8' width='520'/>&quot;;
                videos[3] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/fAa1HZ8dEns' width='520'/>&quot;;
                videos[4] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/2kgjkoYFgNw' width='520'/>&quot;;
                videos[5] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/_IrLxrQNf64' width='520'/>&quot;;
                videos[6] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/z4eredw8_R0' width='520'/>&quot;;
                videos[7] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/ys0UB_YBb_k' width='520'/>&quot;;
                index = Math.floor(Math.random() * videos.length);
                document.write(videos[index]);
               
</script>


3. Or if you want to put on the tag <body>, the fellows shall include
<b:videos id=’videoku’></b:videos>

So the script becomes

<b:videos id=’videoku’>

<script language='JavaScript'>
                videos = new Array(8);
                videos[0] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/MiyFkIGSvhA' width='520'/>&quot;;
                videos[1] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/3wHUyvi0rw0' width='520'/>&quot;;
                videos[2] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/jjpOcYZTpQ8' width='520'/>&quot;;
                videos[3] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/fAa1HZ8dEns' width='520'/>&quot;;
                videos[4] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/2kgjkoYFgNw' width='520'/>&quot;;
                videos[5] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/_IrLxrQNf64' width='520'/>&quot;;
                videos[6] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/z4eredw8_R0' width='520'/>&quot;;
                videos[7] = &quot;<iframe allowfullscreen='allowfullscreen' frameborder='0' height='300' src='http://www.youtube.com/embed/ys0UB_YBb_k' width='520'/>&quot;;
                index = Math.floor(Math.random() * videos.length);
                document.write(videos[index]);
               
</script>

</b:videos>

*Note :
The sign&quot; friends can replace with two quotes (") 
 

Post a Comment