< Back

Document Subject: Browser Window Size
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#BrowserSize or http://A555F9/nn.nsf/ByAlias/BrowserSize

Here is some javascript code to get (and open a new window with ) the web browser's current window size. Works for ie and firefox.




After checking out a few places the best results are gained by using:

document.body.clientHeight  and document.body.clientWidth

These seem to work with all browsers except Netscape 4.

 

document.documentElement.clientHeight and document.documentElement.clientWidth

are also worth trying, but do not work for ie 5 & some ie 6 browsers.

 

I did try:

window.innerHeight  and window.innerWidth

but these do not work with ie at all, and so are pretty useless.

 

I used this with

docprint = window.open(url, "modal", "height="+document.body.clientHeight+", width="+document.body.clientWidth);

docprint.focus();

 

Update: try

document.documentElement.clientHeight

document.documentElement.clientWidth

seems to work on all browsers including IE 7 and 8

 

More Information: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow