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

7th Jul 2019, 12:29 AM
Ginfio
Ginfio - avatar
4 odpowiedzi
7th Jul 2019, 1:48 AM
Manual
Manual - avatar
+ 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.
7th Jul 2019, 1:45 AM
Manual
Manual - avatar
0
Manual that's what i did. it still has the iframe. I waa womdering how to play the video onclick. <button onclick=
7th Jul 2019, 1:50 AM
Ginfio
Ginfio - avatar
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
7th Jul 2019, 4:10 AM
Chris Coder
Chris Coder - avatar