Search code examples
javascriptjqueryiframefullscreen

Auto full screen iframe video without using any api


Is that possible to make "auto full screen a iframe video with out using any api". i already tried youtube api its working well.but i need to know is that possible or not.any explain me with demo please. thank you.

Or any other methods / hacks to achive this solution.


Solution

  • There is a solution with javascript. It's working for Mozilla and Webkit browsers.

    You can use element.mozRequestFullScreen(); and element.webkitRequestFullScreen();

    Example :

    function goFullscreen(id) {
        var element = document.getElementById(id);
    
        if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen();
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen();
       }
    }
    
    <img class="video_player" src="image.jpg" id="player"></img>
    <button onclick="goFullscreen('player'); return false">Fullscreen</button>
    

    To allow fullscreen mode for an <iframe> elements, you need to set your iframe on allowFullScreen :

    <iframe src="iframe.html" width="100" height="100" allowFullScreen></iframe>