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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize client browser window

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
Hello, is there a way to ONLY resize the height of the clients browser window?

Using the "resizeTo(width, height)" function forces you to supply a width value. Initially, I thought, no problem...I'll just pass the current width of the window to the function; however, I can't seem to get that. window.width is undefined, window.innerWidth is underfined, etc, etc. This is being done as the window is being loaded. Any thoughts?

Thanks,
-bitwise
 
Several ways.. You could use "window.resizeBy()" and pass "0" for the width offset. Alternatively, try getting the current width by using one of the following:

Code:
document.getElementsByTagName('body')[0].clientWidth;

Code:
document.getElementsByTagName('body')[0].offsetWidth;

Code:
window.clientWidth;

Code:
window.offsetWidth;

Not sure which will be (a) most accurate, or (b) most compliant with most browsers, so suggest trial-and-error to find out.

Hope this helps,
Dan
 
bitwise,

IMHO, unless this is an intranet system and is mandated by your superiors, changing the users browser size is a no-no. Everybody has their own preferences: I like mine full-screen; others like theirs slight smaller; and still others like theirs smaller still. For you to change the size without the users consent may cause issues to the point of driving them away from your site. Just my opinion.

There's always a better way. The fun is trying to find it!
 
tviman, you are absolutely CORRECT! I hate it when my window is resized automatically. However, this is why I was only attempting to adjust the size on the one axis, namely the height, and ever so slightly. I supposed that the change would be less noticeable and not as easily detected. However, I can't seem to get a consistent width or height value across browsers so I'm scraping the idea. The code, which is called on the "onload" of the body tag, looked like this:

function expandWinHeight() {
var width = document.getElementsByTagName('body')[0].offsetWidth;
var height = document.getElementsByTagName('body')[0].offsetHeight;

//NEED SOME OFFSET BUT VALUES ARE DIFFERENT FOR ANY PARTICULAR BROWSER
//(7 and 121 worked good for me :)
width += ?; //7
height += ?; //121
if(height > 500 && height < 850)
self.resizeTo(width, 850);
}

Personally, I can't believe that you can not simply get the current width and height of the entire browser screen...regardless of the browser. Anyway, thanks both for your help and comments.

-bitwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top