Stop video playing when Bootstrap modal is closed

If you add a video to a Bootstrap Modal and either dismiss or close the modal whilst the video is playing the video will keep on playing.
You can adjust this behaviour by adding in some Bootstrap javascript/jQuery that acts to stop the video if either the modal window is either clicked to close or the background is clicked to dismiss the modal.


jQuery('#myModal1').on('', function (e) {
  // do something...
  jQuery('#myModal1 video').attr("src", jQuery("#myModal1  video").attr("src"));

So change to your modal ID and change your HTML element, here I am using the element video as my selection, but iframe will also be used.

Leave all Comment