停止嵌入 youtube iframe? [英] Stop embedded youtube iframe?

查看:25
本文介绍了停止嵌入 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.

我想使用 javascript 左右单击一个按钮来停止所有这些或其中一个.

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();
  });
});

我明白了:

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.更简单的可能是创建一个类,然后使用 jQuery.each.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆