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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to resize a pop-up window to fit it's contents?

    On a website I use a separate window, popping up, to show the content of a database text field. The height of this window should be set according to the amount of text showed. An onLoad event calls the resize function, which uses the resizeTo command.

    The question is: how to calculate the the correct height?
    I had the idea to place a dummy 1x1 image at the bottom of the page and then determine it's actual Y position. By adding this to the window height without text, I could resize correctly.

    Is this a good solution? If yes, can you give me some coding hints (I'm not very familiar with JavaScript). If no, do you have a better idea?

    Any help is much appreciated.

    Arman

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    dont want to get involved in popups(hate them)

    but
    Code:
    function zxcBdyWH(){
    var x,y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
    	x = document.body.scrollWidth;
    	y = document.body.scrollHeight;
    }
    else // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
    {
    	x = document.body.offsetWidth;
    	y = document.body.offsetHeight;
    }
    
    return [x,y];
    
    }
    will return the document width & height

    can be used to resize the window
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Hello Vic,

    Thank you very much for your help. Apparently, the solution is much simpler than I thought. I've a lot to learn.


  •  

    Posting Permissions

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