Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

javascript - 如何在iframe中嵌入自动播放的YouTube视频?(How to embed an autoplaying YouTube video in an iframe?)

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

(我正在尝试嵌入YouTube视频的新iframe版本并将其设置为自动播放。)

As far as I can tell, there is no way of doing this by amending flags to the URL.

(据我所知,没有办法通过修改URL的标志来做到这一点。)

Is there a way to do it by using JavaScript & the API?

(有没有办法使用JavaScript和API来做到这一点?)

  ask by 472084 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(这适用于Chrome但不支持Firefox 3.6(警告:RickRoll视频):)

<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.

(iframe嵌入JavaScript API存在,但仍作为实验性功能发布。)

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

(更新:现在完全支持iframe API, “创建YT.Player对象 - 示例2”显示了如何在JavaScript中设置“自动播放”。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...