问题
I have a slider that I'm making which displays an image for my post, then when you click it, it makes the image be replaced by an iframe
with a YouTube embed. I want to be able to somehow pause the videos using JavScript (or jQuery) by utilizing the iframes ID. Is there a simple way to do this?
回答1:
You can pause a youtube video.
You can try looking at this code here:
http://jsfiddle.net/3J2wT/757/
HTML:
<a id="pause" href="#">Pause</a>
<iframe id="popup-youtube-player" width="640" height="360" src="http://www.youtube.com/embed/geTgZcHrXTc?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0" allowfullscreen="true" allowscriptaccess="always">
</iframe>
Javascript:
$('#pause').on('click', function() {
$('#popup-youtube-player')[0].contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
});
来源:https://stackoverflow.com/questions/23295860/is-it-possible-to-pause-a-youtube-video-in-an-iframe-using-javascript