Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arn-ob/cca5db64243a157a3ea552ef06b1e593 to your computer and use it in GitHub Desktop.
Save arn-ob/cca5db64243a157a3ea552ef06b1e593 to your computer and use it in GitHub Desktop.
Play a random embedded youtube video
<!DOCTYPE html>
<html>
<head>
<script>
var videos = ["https://www.youtube.com/embed/9bZkp7q19f0", "https://www.youtube.com/embed/dQw4w9WgXcQ"];
window.onload = function () {
var playerDiv = document.getElementById("random_player");
var player = document.createElement("IFRAME");
var randomVideoUrl = videos[Math.floor(Math.random() * videos.length)];
player.setAttribute('width', '640');
player.setAttribute('height', '390');
player.setAttribute('src', randomVideoUrl);
playerDiv.appendChild(player);
};
</script>
</head>
<body>
<div id="random_player" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment