0
J.S. | HTML how to play YouTube video onclick?
We use iframe to put YouTube videos in our web, Is there a way to play it onclick (button)? My attempt: https://code.sololearn.com/W9U2RvzphXyc/?ref=app
4 odpowiedzi
+ 3
More info here.
https://support.google.com/youtube/answer/171780?hl=en
+ 2
You do not need ifame for that.
You do not need to add anything either.
Go to youtube. Find a video. Press share. Copy the embeded code.
0
Manual that's what i did. it still has the iframe.
I waa womdering how to play the video onclick.
<button onclick=
0
I see that you want to use buttons to control the video.
I found an example that uses API. However, the code does not appear to work in codeplayground. But works on Codepen.
You're welcome to give it a try.
https://codepen.io/imelgrat/pen/MrZRPe
You can change your video by editing line 14 in the JS. Just add the video id.
so6Vb0DqsG0
You can read more about the API here
https://www.htmlgoodies.com/beyond/video/respond-to-embedded-youtube-video-events.html