Javascript to stop HTML5 video playback on modal window close

The Solution to Javascript to stop HTML5 video playback on modal window close is


I'm using the following trick to stop HTML5 video. pause() the video on modal close and set currentTime = 0;

<script>
     var video = document.getElementById("myVideoPlayer");
     function stopVideo(){
          video.pause();
          video.currentTime = 0;
     }
</script>

Now you can use stopVideo() method to stop HTML5 video. Like,

$("#stop").on('click', function(){
    stopVideo();
});

~ Answered on 2013-11-15 16:30:09


Most Viewed Questions: