Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop embedded 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.

Is it possible?

UPDATE:

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'  
like image 577
Danpe Avatar asked Mar 01 '13 19:03

Danpe


People also ask

How do I remove the embedded YouTube logo?

You can add ? modestbranding=1 to your url. That will remove the logo. This parameter lets you use a YouTube player that does not show a YouTube logo.


1 Answers

Unfortunately these API's evolve very fast. As of May 2015, the proposed solutions don't work anymore, as the player object has no stopVideo method.

A reliable solution is to be found in this page (1) and it works with an:

<iframe id="youtube_player" class="yt_player_iframe" width="640" height="360" src="http://www.youtube.com/embed/aHUBlv5_K8Y?enablejsapi=1&version=3&playerapiid=ytplayer"  allowfullscreen="true" allowscriptaccess="always" frameborder="0"></iframe> 

and the following JS/jQuery code:

$('.yt_player_iframe').each(function(){   this.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*') }); 
like image 88
Marco Faustinelli Avatar answered Sep 30 '22 12:09

Marco Faustinelli