I have used a iframe video
in my web page. This is my html code
<iframe id="video1" width="520" height="360" src="http://www.youtube.com/embed/TJ2X4dFhAC0?enablejsapi" frameborder="0" allowtransparency="true" allowfullscreen></iframe>
<a href="#" id="playvideo">Play video</a>
I need to play
video onclick
the play video link. How can i do that?
Here is another example. Check this here: https://codepen.io/rearmustak/pen/VXXOBr
since the first answer is already 3 years old, let me point to the Youtube Player API. With that you can remote control your embedded player. See https://developers.google.com/youtube/iframe_api_reference?hl=en
With a small adjustment, you can start the video via link and without reloading the entire iframe:
I correctly set in end src - ?autoplay=1
here is link to example http://jsfiddle.net/WYwv2/5/
Check out this
We set the source of video dynamically.
This works, it appends
autoplay=1
to the url causing the video to start playing.addendum: If your video's source does not already have a querystring then it would be prudent to add a
?
instead of a&
, as is sometimes the case. This can be done by looking for its existence.However, most people inherently understand that if they want a video to play, they will just click on it and I would suggest just leaving that to them or starting the video off with autoplay.
Also need to mention that autoplay does not work on mobile devices (powered by Android or iOS)