Forum Moderators: open

Message Too Old, No Replies

How to get window size

         

waitt

1:52 am on Sep 7, 2004 (gmt 0)

10+ Year Member



It's a holiday and I'm probably brain dead. This is probably a simple one. I'm trying to write a general function to center a window on the screen. How do I determine the size (height,width) of a window?

I've tried window.height and window.width, but they don't seem to be defined for the window object.

user9

7:55 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



Hi waitt,

Try the following page.

[javascript.internet.com...]

It's code generator that optionally centers windows

waitt

8:57 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



user9,

Thanks for the info, but this code generator opens a new window and centers the window based on the size it was given in the form. I need to be able to determine the size of an existing window that was opened by some other page in my application.

Thanks
waitt

Bernard Marx

9:20 pm on Sep 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Getting the outer win dims is easy in Mozilla:

window.outerWidth
window.outerHeight

[mozilla.org...]

In IE, I'm not sure it's possible (correct me if..).
However, assuming that the chrome is even - left & right - the clientWidth will do for left centering (ed: Nah, what do I mean. It'll have to be a guess). Vertical centering may have a problem, unless you actually resize the window yourself.

The clientWidth/Height (corresp.to window.innerHeight in Moz) is a property of the body or documentElement depending on the mode. It's likely that you won't be able to test these properties until after page load.

Check out QuirksMode on the subject:

[quirksmode.org...]
and HowToCreate
[howtocreate.co.uk...]