How to make an embedded Youtube video automatically start playing?

Saritha picture Saritha · Mar 18, 2011 · Viewed 195.6k times · Source

In my project, there is a video gallery module. In this module, there are two options: direct FLV uploading, and adding a video embed code from YouTube.

I am writing some embed code for a div element (actually, the embed code comes from database). I want to make this video begin playing automatically.

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/zGPuazETKkI" frameborder="0" allowfullscreen></iframe>

This is a sample embed code from YouTube. I want to make this video play automatically using JavaScript.

Answer

Alex Bailey picture Alex Bailey · Mar 18, 2011

You have to use

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/zGPuazETKkI?autoplay=1" frameborder="0" allowfullscreen></iframe>

?autoplay=1

and not

&autoplay=1

its the first URL param so its added with a ?