Answer the question
In order to leave comments, you need to log in
Stop (turn off) youtube video on click on body?
Hello Lord.
There are several youtube videos on the page. I needed that when you click on a picture that has its own id, the video, which also has its own id, starts playing. I found this script on the internet:
<script>
$(document).on('click', '.open_window', function() {
var $video = $('#you_video'),
src = $video.attr('src');
$video.attr('src', src + '&autoplay=1');
});
</script>
<script>
$(document).on('click', 'body', function() {
var $video = $('#you_video'),
src = $video.attr('src');
$video.attr('src', src + '&autoplay=0');
});
</script>
Answer the question
In order to leave comments, you need to log in
I found such a solution who will need to use it, just put your classes or id:
<script>
$(document).on('click', '.open_window', function() {
var $video = $('#you_video'),
src = $video.attr('src');
$video.attr('src', src + '&autoplay=1');
});
</script>
<script>
$(document).on('click', '.overlay', function(){
jQuery("iframe").each(function() {
jQuery(this)[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*')});
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question