41

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.

2540625
  • 11,022
  • 8
  • 52
  • 58
Saritha
  • 1,947
  • 5
  • 18
  • 24

4 Answers4

73

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 ?

DLJ
  • 333
  • 2
  • 6
  • 19
Alex Bailey
  • 1,679
  • 10
  • 15
  • 1
    thanks this worked for me! this was inserted right after the embed code from You tube. ;autoplay=1" this was the original code: It worked when the edit was inserted behind the: rel=0" before the frameborde – chuck Mar 12 '13 at 01:19
  • Only way I could get this to work was by removing the `rel=0` param. (not sure what that does anywho). – Tony Beninate Jul 10 '13 at 17:42
  • 1
    `rel=0` removes the related suggested videos at the end. – Katharine Osborne Nov 27 '15 at 19:04
6

This works perfectly for me try this just put ?rel=0&autoplay=1 in the end of link

<iframe width="631" height="466" src="https://www.youtube.com/embed/UUdMixCYeTA?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
Jamil Ahmed
  • 419
  • 4
  • 11
4
<iframe title='YouTube video player' class='youtube-player' type='text/html'
        width='030' height='030'
        src='http://www.youtube.com/embed/ZFo8b9DbcMM?rel=0&border=&autoplay=1'
        type='application/x-shockwave-flash'
        allowscriptaccess='always' allowfullscreen='true'
        frameborder='0'></iframe>

just insert your code after embed/

sth
  • 222,467
  • 53
  • 283
  • 367
gracie b
  • 41
  • 1
3

Add &autoplay=1 to your syntax, like this

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/zGPuazETKkI&amp;autoplay=1" frameborder="0" allowfullscreen></iframe>
nardocesar
  • 91
  • 3
  • 7
    According to related questions you would want to add `?autoplay=1`. As is standard in URL paramters, the first is identified by an `?` and other appended using the `&` symbol. – blo0p3r Dec 20 '12 at 18:47