ian
1
I have embedded a video inside a modal and everything is working but I have a question.
Question:
When the modal is open and the video is playing, when I press Close to close the Modal, the video continues to play.
Does anyone know of a way to stop the video when the Close button is pressed ?
catkin
2
Is this a standard HTML5 video embed, or is it a YouTube video ect?
ian
3
Sorry should have said, its embedded in an iFrame
ian
4
It turns out this cannot be done when a video is embedded unless you can target the API
I moved the video into a
Ian
This JS script will stop a video playing in an iframe in a modal when the modal is closed. 
var modals = document.querySelectorAll(‘.modal’);
modals.forEach(function(modal) {
modal.addEventListener(‘hide.bs.modal’, function() {
var iframe = modal.querySelector(‘iframe’);
if (iframe) {
iframe.src = iframe.src;
}
});
});
1 Like
ian
6
Thank you for that, rally appreciated. I shall implement that today as I prefer to use an embedded video for this project I am working on.
Ian