How to stop the (youtube) video on click? I've tried so much, but I can't get it working … what am I doing wrong? Regarding to the docs and hundreds of posts in the internet this should work like a charm … but it does not:
html:
<iframe width="420" height="315" src="https://www.youtube.com/embed/2BagaJFimzk?autohide=1&showinfo=0&rel=0&enablejsapi=1&origin=http%3A%2F%2Fjsfiddle.net" frameborder="0" allowfullscreen></iframe>
<button>please stop :(</button>
in js (with jquery and youtube-api loaded):
var thisvid;
function onYouTubePlayerAPIReady() {
thisvid = new YT.Player($('iframe')[0]);
}
if (!thisvid) onYouTubePlayerAPIReady();
$('button').click(function () {
thisvid.pauseVideo();
});
on jsfiddle
I can't create the video-iframe with JS … so I need a solution for a given iframe.
THX in advance!