Search code examples
javascriptfullscreen

How to make the window full screen with Javascript (stretching all over the screen)


How can I make a visitor's browser go fullscreen using JavaScript, in a way that works with IE, Firefox and Opera?


Solution

  • This is as close as you can get to full screen in JavaScript:

    <script type="text/javascript">
        window.onload = maxWindow;
    
        function maxWindow() {
            window.moveTo(0, 0);
    
            if (document.all) {
                top.window.resizeTo(screen.availWidth, screen.availHeight);
            }
    
            else if (document.layers || document.getElementById) {
                if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
                    top.window.outerHeight = screen.availHeight;
                    top.window.outerWidth = screen.availWidth;
                }
            }
        }
    </script>