View Full Version : How to resize a pop-up window to fit it's contents?

08-09-2006, 09:45 AM
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.


08-09-2006, 11:17 AM
dont want to get involved in popups(hate them)


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

08-10-2006, 09:16 AM
Hello Vic,

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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum