javascript 播放 YouTube 视频的超链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3614489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hyperlink to play youtube video
提问by neojakey
Is it possible to create a hyperlink on your web page that can play an embedded youtube video on the same page.?
是否可以在您的网页上创建一个可以在同一页面上播放嵌入式 YouTube 视频的超链接。?
采纳答案by Marko
you can easily do this with the Youtube Player API
您可以使用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
然后在你的 HTML 中简单地
<a href="#" onclick="play()">Play Youtube Video</a>

