How to Resize to Full Screen in Javascript

Save

JavaScript does not have a way to maximize the window for web browsers. "Maximize," meaning to access the Windows Maximize control to open the window. JavaScript can resize the window, but the whole screen is not covered. It is considered bad Internet etiquette to maximize the window during the initial page load. It is better to code a button that will maximize the window when it is clicked, or to have a message telling the user to press the "F11" key to maximize the browser window.

Open Window

  • Create the function you will call to open the full-screen window. In this example we will call the function, "Max_window()." Type the code as follows:

    <script>

    function Max_window(){

    window.moveTo(0,0)

    window.resizeTo(screen.width,screen.height)

    }

    </script>

  • Locate the area in the program to call the function.

  • Type "Max_window()" to call the function you created.

Open Window on Page Load

  • Open your HTML editor of choice.

  • Type the code below the <HEAD> tag as follows:

    <script language="JavaScript">

    window.onload = Max_window;

    function Max_window()

    {

    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>

  • Test the code in your browser.

Tips & Warnings

  • The "document.all" works for Interet Explorer. If you want to write the code for FireFox then use "document.layers" instead.

References

Promoted By Zergnet

Comments

Resources

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!