Search code examples
htmlvideo

Full screen video toggle HTML


The video tag in HTML 5 is really fascinating. I need to know whether it is possible to let users toggle full screen play. I dont wanna use any other video plugin. I just need to use the video tag. So is this possible. Please help me out....


Solution

  • You can use the following code to create a button that will take the video into full screen mode.

    Javascript code:

    <script type="text/javascript">
    function goFullscreen(id) {
      var element = document.getElementById(id);       
      if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
      } else if (element.webkitRequestFullScreen) {
        element.webkitRequestFullScreen();
      }  
    }
    </script>
    

    Html code:

    <video class="video_player" id="player" width="100%" controls="controls" autoplay="autoplay">
      <source src="INPUT VIDEO URL HERE"/>
      Your browser does not support the HTML5 video tag.  Use a better browser!
    </video>
    <button onclick="goFullscreen('player'); return false">
      View Fullscreen!
    </button>