G
G
Gregory Didus2015-08-11 12:06:26
YouTube
Gregory Didus, 2015-08-11 12:06:26

How to stop youtube video from playing in JS using JS?

Hello!

<iframe width="800" height="480" src="https://www.youtube.com/embed/" frameborder="0" allowfullscreen id="youtube"></iframe>
- so the video is inserted on the page.
I want the video on the page to stop on the "onclick" event on certain elements.
Please tell me how exactly to implement the stop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Baev, 2015-08-11
@Suicide676

Not exactly trivial, but nonetheless:
In the video download url add ?enablejsapi=1
Then stop the video, in the event you need:

document.getElementById('video').contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question