Click to See Complete Forum and Search --> : Dynamic height of window


darcsinx
12-05-2003, 08:14 AM
Hi,

I'm new to JavaScript but not to programming ;)
What I'm doing is a little system where clients have little pop-up window open on their PC which displays information.

That window retreives textual information from a database once a minute. So the information in the window is dynamic and it automatically updates itself.

What I'm thinking about is letting this window (which has no toolbar, statusbar etc.) have fixed width but dynamic height depending on the information needed to be displayed.

So instead of having scrollbars and having the user scroll up/down I want the window to display all information each time...so if information is added to the database...next time the window retrieves this information it gets higher). In other words, no interaction from the user.

Is this possible, the application is otherwise written in PHP....hope you understand what I mean!!

Gollum
12-05-2003, 08:28 AM
Sure you can!

what you need to do is first put a <div> around all of your content...

<body onload="setHeight();">
<div id=surround style="width:300">
... all your data goes here
</div>
</body>


the onload in your body tag calls the function setHeight()...

function setHeight()
{
// calculate current client area
var ch;
if ( document.body.clientHeight )
{
ch = document.body.clientHeight;
}
else if ( window.innerHeight )
{
ch = window.innerHeight;
}
else
{
return;
}

var margin = 30;

var y;
var oSurround = document.getElementById('surround');
if ( oSurround.offsetHeight )
{
y = oSurround.offsetHeight;
}
else if ( oSurround.naturalHeight )
{
y = oSurround.naturalHeight;
}
else
{
return;
}

top.window.resizeBy(0,y+margin-ch);
top.window.focus();
}

darcsinx
12-05-2003, 10:12 AM
Thank you, that certainly got me going and this works fine to some extent. Firstly, I have to move the window after I resize it so it always stays in the bottom left corner...not very hard and I'll figure that out myself (using moveTo)

The other problem is that I have to try to get it to work in Netscape 4.79...yes that's Netscape 4 :mad:

Any suggestions about how to accomplish that, or if it is even possible !!?!

darcsinx
12-09-2003, 08:15 AM
Anyone, I'm having some trouble getting this to work in Netscape 4, i.e. getting the size between <div> tags

And, yes, I'm lazy :D