Results 1 to 5 of 5

Thread: resize and center window?

  1. #1
    Join Date
    Nov 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post resize and center window?

    hey guys, im looking for a script that can resize the window its in, like this

    <script language="JavaScript">
    <!--
    function resize_400x300()
    {
    window.resizeTo(400,300)
    }
    -->
    </script>


    with any size, but i would also like that window to be centered? Is it possible?
    any help would be much helpfull!
    thanks.

    -peej

  2. #2
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Code:
    function resizeAndCenter(width, height) {
    	window.resizeTo(width, height);
    	window.moveTo((screen.availWidth-width)/2, (screen.availHeight-height)/2);
    }
    
    resizeAndCenter(400, 300);

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    If screen.availWidth-width is an odd number, when you divide it by two, wouldn't that cause an error? (where it'll be a decimal)
    eg: trying to set the screen left to 35.5
    - Mike

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You are much better off devising a better way of designing your page so that such javascript dependant schemes are not required.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking thanks.

    thanks DimX, works great!

Bookmarks

Posting Permissions

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