Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    2
    Thanked 1 Time in 1 Post

    Open and center window function

    100% working code for you to copy and paste:
    Code:
    function openWindow(the_url, the_size)
    {  
        var screen_height = window.screen.availHeight;
        var screen_width = window.screen.availWidth;
        var left_point = parseInt(screen_width / 2) - (the_size / 2);
        var top_point = parseInt(screen_height / 2) - (the_size / 2);
        var the_features = "width=" + the_size + ",height=" + the_size + ",top=" + top_point + ",left=" + left_point;
        var the_window = window.open(the_url, "", the_features);
    }
    example use
    Code:
    <a href = "#" onClick = 
        "openWindow('http://www.http://bookofjavascript.com/', 500); return false;">Click me to open book of Java Script</a>

    full example:
    Code:
    <html>
    <head>
    <title>Functions</title>
    <script type = "text/javascript">
    <!--
    //open and center window function based on bookofjavascript.com by thau! 
    //modified by Spidey1980 for reusability
    function openWindow(the_url, the_size)
    {  
        var screen_height = window.screen.availHeight;
        var screen_width = window.screen.availWidth;
        var left_point = parseInt(screen_width / 2) - (the_size / 2);
        var top_point = parseInt(screen_height / 2) - (the_size / 2);
        var the_features = "width=" + the_size + ",height=" + the_size + ",top=" + top_point + ",left=" + left_point;
        var the_window = window.open(the_url, "", the_features);
    }
    // -->
    </script>
    </head>
    <body>
    <a href = "#" onClick = 
        "openWindow('http://www.http://bookofjavascript.com/', 500); return false;">Click me to open book of Java Script</a>
    </body>
    </html>
    Last edited by Spidey1980; 01-11-2012 at 06:11 PM. Reason: details


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •