如何在iframe中嵌入自动播放的YouTube视频? [英] How to embed an autoplaying YouTube video in an iframe?

查看:784
本文介绍了如何在iframe中嵌入自动播放的YouTube视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试嵌入新的iframe版本的YouTube视频,并使其自动播放.

据我所知,没有办法通过将URL的标志修改来做到这一点.有没有一种方法可以通过使用JavaScript& API?

解决方案

此方法在Chrome浏览器中有效,但在Firefox 3.6中无效(警告:RickRoll视频):

<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>

用于iframe嵌入的JavaScript API 存在,但仍作为实验性功能发布. /p>

更新:现已完全支持iframe API,并且创建YT.Player对象-示例2" 显示如何在JavaScript中设置自动播放".

I am trying to embed the new iframe version of a YouTube video and get it to auto play.

As far as I can tell, there is no way of doing this by amending flags to the URL. Is there a way to do it by using JavaScript & the API?

解决方案

This works in Chrome but not Firefox 3.6 (warning: RickRoll video):

<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>

The JavaScript API for iframe embeds exists, but is still posted as an experimental feature.

UPDATE: The iframe API is now fully supported and "Creating YT.Player objects - Example 2" shows how to set "autoplay" in JavaScript.

这篇关于如何在iframe中嵌入自动播放的YouTube视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆