是否可以使用JavaScript在iframe中暂停YouTube视频? [英] Is it possible to pause a YouTube video in an iframe using JavaScript?
本文介绍了是否可以使用JavaScript在iframe中暂停YouTube视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我制作的滑块,它为我的文章显示图像,然后当您点击它时,图像将被 iframe
替换为YouTube嵌入。我希望能够通过利用iframes ID以某种方式使用JavScript(或jQuery)暂停视频。有没有一种简单的方法来做到这一点?
解决方案
您可以暂停YouTube视频。
你可以在这里查看这段代码:
http://jsfiddle.net/3J2wT/757/
HTML:
< a id =pausehref =#>暂停< / a>
< / iframe>
Javascript:
< $('#pause')。on('click',function(){
$('#popup-youtube-player')[0] .contentWindow.postMessage( '{event:command,func:'+'pauseVideo'+',args:}','*');
}); 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?
解决方案
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":""}', '*');
});
这篇关于是否可以使用JavaScript在iframe中暂停YouTube视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文