Stopping Video Inside Modal

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 ?

Is this a standard HTML5 video embed, or is it a YouTube video ect?

Sorry should have said, its embedded in an iFrame

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. :slightly_smiling_face:

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

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