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?
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'
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.
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":""}', '*') });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With