I'm trying to make back and next buttons for, in this case, an iframe. Here is my code:
<script>
var array=["npvNPORFXpc", "CcsUYu0PVxY", "dE_XVl7fwBQ", "iIwxR6kjTfA", "USe6s2kfuWk"];
var iframe = document.getElementById('frame');
var previousRandom = "npvNPORFXpc"; // initial video
document.getElementById('random').addEventListener('click', function () {
do {
var random = array[Math.floor(Math.random() * array.length)];
}
while (previousRandom === random)
var url="http://www.youtube.com/embed/"+random;
previousRandom = random;
iframe.src = url;
});
</script>
With a bit of HTML:
<button id="random">Random</button><br>
<iframe id="frame" src="http://www.youtube.com/embed/npvNPORFXpc" width="640" height="360" frameborder="0" allowfullscreen></iframe>
So I want to create two buttons, one for going to the next video in the var array and a second for the previous video in the var array.
I just started with JS and couldn't find an example that I understood.
Should have started with the basics of JS instead of this project, but still would like to finish this!
HTML:
JS:
Working example: http://jsfiddle.net/z47XP/
Example using the example that I pointed you at.
CSS
HTML
Javascript
On jsFiddle