停止嵌入youtube iframe? [英] Stop embedded youtube iframe?
问题描述
我使用YouTube iframe在我的网站上嵌入视频。
I'm using YouTube iframe to embed videos on my site.
<iframe width="100%" height="443" class="yvideo" id="p1QgNF6J1h0"
src="http://www.youtube.com/embed/p1QgNF6J1h0?rel=0&controls=0&hd=1&showinfo=0&enablejsapi=1"
frameborder="0" allowfullscreen>
</iframe>
我在同一页面上放映多个视频。
And i have multiplie videos on the same page.
我想要停止所有这些或他们中的一个,只需点击一下按钮即可。
I want to stop all of them or one of them in a click of a button using javascript or so.
可能吗?
我尝试了 Talvi Watia 表示和使用:
I tried what Talvi Watia said and used:
$('#myStopClickButton').click(function(){
$('.yvideo').each(function(){
$(this).stopVideo();
});
});
我得到:
I'm getting:
Uncaught TypeError: Object [object Object] has no method 'stopVideo'
推荐答案
您可能希望通过 Youtube JavaScript API 参考文档进行检查。
You may want to review through the Youtube JavaScript API Reference docs.
当您在视频中嵌入视频时,您需要传递此参数:
When you embed your video(s) on the page, you will need to pass this parameter:
http://www.youtube.com/v/VIDEO_ID?version=3&enablejsapi=1
如果您想要停止所有视频按钮,您可以设置一个JavaScript例程来循环播放视频并停止它们:
If you want a stop all videos button, you can setup a javascript routine to loop through your videos and stop them:
player.stopVideo()
这包括跟踪所有页面ID网页上的每个视频。
This does involve keeping track of all the page IDs for each video on the page. Even simpler might be to make a class and then use jQuery.each.
$('#myStopClickButton').click(function(){
$('.myVideoClass').each(function(){
$(this).stopVideo();
});
});
这篇关于停止嵌入youtube iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!