Results 1 to 2 of 2

Thread: resizing

  1. #1
    Join Date
    May 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default resizing

    Hi, I'm trying to dynamically resize a window's height based on the content, this it what I have, but it's not working.

    var H=document.body.clientHeight;
    window.resizeTo( 220 , H );

  2. #2
    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

    That might work in IE on a page with no doctype, sort of. The expression 'clientHeight' is an IE proprietary one that measures the height of the window. So, on browsers that support it, you are measuring the current height of the window and then setting the height to it. If you wrap your page in a division tag, so instead of:
    HTML Code:
    <body>
    
    content goes here
    
    </body>
    you use:
    HTML Code:
    <body>
    <div>
    
    content goes here
    
    </div>
    </body>
    You can use this handy piece of code:
    Code:
    var H = document.getElementsByTagName('div')[0].offsetHeight;
    window.resizeTo( 220 , H );
    Using:
    Code:
    document.getElementsByTagName('body')[0].offsetHeight;
    should work but IE doesn't 'get it' unless you use at least a transitional doctype, Mozilla based browsers have no problem recognizing it.

    Added Later:

    You will still have to add about 150 to H to allow for the window's chrome.
    Last edited by jscheuer1; 05-28-2005 at 07:00 PM.
    - John
    ________________________

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

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
  •