Is it possible to create a hyperlink on your web page that can play an embedded youtube video on the same page.?
Asked
Active
Viewed 1.8k times
18
-
1I'm not sure this is valid for `iframe` objects in-use at this time. – New Alexandria Jan 30 '13 at 17:44
1 Answers
12
you can easily do this with the Youtube Player API
If you have a read through that document, you'll see it's pretty easy to have your own controls and extend the player.
Example
// Get element holding the video (embed or object)
var player = document.getElementById("myYouTubePlayer");
//Create a simple function and check if player exists
function play() {
if(player) {
player.playVideo();
}
}
Then in your HTML simply
<a href="#" onclick="play()">Play Youtube Video</a>

Marko
- 71,361
- 28
- 124
- 158
-
-
Is there a jsfiddle version of this anywhere? Thanks for answering the question – Mike Aug 31 '12 at 08:49
-
1