Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window sizing

Status
Not open for further replies.

camelman

Programmer
May 31, 2001
32
ZA
I am trying to do a write a few scripts relating to the sizing of a browser window.
1) How do I get the width and height of an IE window ? I tried using window.innerwidth but apparently it only works in netscape.
2) I need my window to resize according to a ratio ie: If the user tries to make the window shorter, it also gets narrower (higher gets wider etc.)

screen.width seems to get the width of the screen so why on earth could they not just include a window.width property.

This has been causing me to lose hair for the past week (and I am only in my twenties) so if anyone can help me I would be very grateful.

 
OK - so after hours of searching the web I figure out the clientwidth and clientheight properties.

I still can't seem to work out how to resize according to a ratio.
The problem being that now that now that I have the size of the window, how do I know what was being done to the window.

If the window was made shorter or taller, I need to know this in my script in order to size the window according to a ratio.
Also, I used an onResize function to ensure that they don't make the window bigger than a set size but it doesn't work very
nicely. If the user is persistant enough with dragging the window it still gets bigger. Strange huh ?

This is my size checking function which runs on starting the site and on resizing the window.

var MaxWinHeight = 400;
var MaxWinWidth = 400;

// this function checks the screen size and ensures it isn't greater than the maximum.
function toobig() {
var w = document.body.clientWidth;
var h = document.body.clientHeight;
var change_size = false;

if(w>MaxWinWidth){
w=MaxWinWidth;
change_size = true;
}

if(h>MaxWinHeight){
h=MaxWinHeight;
change_size = true;
}

if(change_size==true){
window.resizeTo(w, h);
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top