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.

Javascript

<script>
jQuery('#myModal1').on('hidden.bs.modal', function (e) {
  // do something...
  jQuery('#myModal1 video').attr("src", jQuery("#myModal1  video").attr("src"));
});
</script>

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