Имеется модальное окно в котором есть видос с ютуба вставленный через iframe и кнопка закрывающая это модальное окно.Но есть баг,при закрытии этого модального окна видео продолжает играть в фоне.Как его останавливать вместе с закрытием??
HTML код модального окна:
<div class="modWindow">
<div class="win">
<img src="" alt="">
<iframe src="" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat molestias alias, earum pariatur dolores illo quod voluptates iure rem deleniti?
</p>
<button class="btn btn-outline-danger" id="closeModWindow">Close</button>
</div>
</div>
Код открытия модального окна:
videoList.onclick = function(e){
let target = e.target.closest("div");
if(target.className != 'preview') return;
modalWindow.querySelector("iframe").style.display = 'flex';
modalWindow.querySelector("img").style.display = 'none'; //скрывать img в случае,если модальное окно вызывается для видео
modalWindow.querySelector("iframe").src = target.dataset.videoSrc;
modalWindow.style.display = 'flex';
};
Код закрытия модального окна:
buttonClose.onclick = function(){
modalWindow.style.display = 'none';
};