# Determining the Screen Dimensions

The screenthat glowing, slightly rounded panel you stare at all dayis where all the windows that make up your Web site reside. You can try making Web sites with Morse code or punch cards, but trust me on this one: The computer monitor is currently the best medium for displaying Web sites.

One of the frustrations of Web design, however, is never knowing the size of the area in which your design will be placed or how much space is actually available. To find out how much space you're working with, you can use the screen.width and screen.height objects (Figure 13.16) to find the total dimensions of the screen, and the screen.availWidth, and screen.availHeight (Figure 13.17) objects to find the actual available space on the screen, once menus and other interface elements are taken into account (Figures 13.18 and 13.19).

##### Figure 13.19. The live area of the Mac OS X screen is everywhere but the top menu bar and approximately 6 pixels on the left and right sides. The Mac OS always displays a menu bar at the top of the screen.

So why don't you just ask the screen how big it is (Figure 13.20)?

##### Figure 13.20. The code displays both the total and live dimensions of the screen for my computer.

To find the screen's dimensions:

1.

`screen.height;`

Add the variables screenHeight and screenWidth to your JavaScript, and assign to them the values screen.height and screen.width, respectively. These variables will now record the total height and width of the screen, in pixels (Code 13.5).

##### Code 13.5. This code determines both the total and the live dimensions of the entire screen and assigns these values to variables, which it then uses to write the values in the browser window.

 [View full width]` CSS, DHTML & Ajax | Finding the Screen Dimensions `

2.

`screen.availHeight;`

Add the variables liveScreenHeight and liveScreenWidth to your JavaScript, and assign to them the values screen.availHeight and screen.availWidth, respectively.

These variables will now record the live (available) height and width of the screen, in pixels. This differs from the total, in that it does not include any menu bars added by the OSonly the area in which windows can be displayed.

CSS, DHTML, and Ajax, Fourth Edition
ISBN: 032144325X
EAN: 2147483647
Year: 2006
Pages: 230

Similar book on Amazon