1. Computing & Technology

JavaScript By Example

Browser Object Model: 8. Screen Size

From , former About.com Guide

A lot of people get confused between the screen size and the browser viewport size. Except if you are suggesting a size for opening a new window or are resizing or moving an existing window the actual screen size is not at all relevant since the only area that the web page has to deal with is the area in the browser viewport.

JavaScript provides the screen object to access information about the screen. While different browsers may add their own properties there are generally at least the following five available that can be used - width and height give the actual screen resolution in pixels, availWidth and availHeight give the actual area of the screen usable by programs after deducting for any fixed toolbars and colorDepth tells you the number of bits available to store the colour of each pixel (usually 32 on all modern computers).

This example shows you how to suggest that the new window being opened should be openned to fill as much of the screen as possible (typically the entire screen except for the area used by the taskbar across the bottom of the screen).


window.open('next.htm','javascriptabout',
'top=0,left=0,'+
'width='+screen.availWidth+',height='+screen.availHeight,
true);

©2012 About.com. All rights reserved.

A part of The New York Times Company.