Exiting Fullscreen With The HTML5 Video Tag

后端 未结 3 1420
小蘑菇
小蘑菇 2020-12-28 10:50

I\'m trying to get the video to exit fullscreen at the end of the video but it won\'t. I searched and found ways to do this but for the life of me I can\'t get it to work. I

3条回答
  •  渐次进展
    2020-12-28 11:14

    I know this is already answered, but here is the little code snippet I ended up using for all browsers to close fullscreen video after it ends.

    Works on Chrome, IE11, Firefox so far:

    $("#myVideoTag").on('ended', function(){
        if (document.exitFullscreen) {
            document.exitFullscreen(); // Standard
        } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen(); // Blink
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen(); // Gecko
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen(); // Old IE
        }
    });
    

    You can also find the current full screen element (if any) like:

      var fullscreenElement = document.fullscreenElement || 
       document.mozFullScreenElement || document.webkitFullscreenElement;
    

    Source: https://www.sitepoint.com/use-html5-full-screen-api/

    Just thought I would add the answer as this was the first question I came across when looking for a solution to this.

提交回复
热议问题