阻止iframe播放YouTube视频 [英] Prevent iframe playing youtube video
问题描述
iframe中是否有阻止它播放视频的选项,即我具有以下iframe:
Is there an option in iframe to prevent it from playing video i.e. I have following iframe:
<iframe src="https://www.youtube.com/embed/v2ifWcnQs6M" width="468" height="60" ></iframe>
我只想在缩略图的中心显示带有红色播放"按钮的youtube视频的缩略图,但不允许用户实际播放视频.有办法吗?
I want to display just the thumbnail of youtube video with red 'play' button in the center of thumbnail, but disallow user to actually play video. Is there a way to do it ?
因为我检查了 Youtube IFrame API ,所以没有解决方案来获取youtube视频ID,即我必须自己解析网址,然后构造以下网址:
Because as I checked Youtube IFrame API there is no solution for getting youtube video id i.e. I have to parse url by myself and then construct the following url:
https://img.youtube.com/vi/video_id/0.jpg
此外,此网址还返回没有红色播放"按钮的缩略图,这也是我想要的.那么在iframe或js解决方法中是否有HTML属性可以做到这一点?
And besides this url returns thumbnail without red 'play' button which I also want. So is there an HTML attribute in iframe or js workaround to do it ?
推荐答案
在具有CSS的YouTube视频顶部添加一个透明的div. 请参见示例.
Add a transparent div on top of the YouTube video with CSS. See example.
这篇关于阻止iframe播放YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!