Sunday, January 25, 2009

Detecting user's screen size using window.screen

JavaScript supports a window.screen object that contains basic information about the screen of your visitor. With this information, pages could be designed to custom fit the particularities of each screen. In this article, we will see just how easy it is to detect a user's screen type!.

All screen information is stored in the screen object of JavaScript, a new object. They are in the form of properties:

Properties:
availHeight : Specifies the height of the screen, in pixels, minus interface features such as the taskbar in Windows.

availWidth : Specifies the width of the screen, in pixels, minus interface features such as the taskbar in Windows.

colorDepth : The bit depth of the color palette available for displaying images in bits per pixel.

height : The total height of the screen, in pixels.

pixelDepth : Display screen color resolution (bits per pixel). Firefox exclusive property.

width : The total width of the screen, in pixels.

Each property is accessed just like any other, first the name of the object, than the property it self:
screen.width

No comments:

Post a Comment