如何使用 Javascript 捕捉 youtube 视频播放器的播放/暂停事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12869334/
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
How to catch youtube video player's Play/Pause event using Javascript?
提问by aslamdoctor
Possible Duplicate:
Make callback after play button is pushed - Youtube embed video
I have a Youtube video embeded on my website. The code is as below
我的网站上嵌入了一个 Youtube 视频。代码如下
<iframe width="280" height="180" frameborder="0" src="http://www.youtube.com/embed/U5BVeZybEV4" title="YouTube video player" allowfullscreen></iframe>
What I want to do is, when I click on Playbutton of the Video, it should execute a javascript alert function as
我想要做的是,当我点击视频的播放按钮时,它应该执行一个 javascript 警报功能
alert("Clicked Play");
Same way, if I click on Pause button, it should execute a javascript alert function as
同样的方式,如果我点击暂停按钮,它应该执行一个 javascript 警报功能
alert("Clicked Pause");
Any suggestion how can I catch these Events ?
有什么建议我怎么能赶上这些事件?
Thanks in advance.
提前致谢。
回答by aslamdoctor
Check this example below, we can do it using Youtube Player API
检查下面的这个例子,我们可以使用 Youtube Player API