Categories:

JavaScript Kit > JavaScript Reference > Here

Screen Object

Last updated: January 14th, 2009

Use the screen object of JavaScript to derive basic information about the user's screen, such as dimensions.

Related Tutorials

Properties

Properties Description
availWidth Specifies the width of the screen, in pixels, minus interface features such as the taskbar in Windows.
availHeight Specifies the height of the screen, in pixels, minus interface features such as the taskbar in Windows. A practical usage of this property is to open a window using JavaScript that's maximized to the user's entire screen while not covering up the Windows taskbar, since availWidth and availHeight factors them out in their values.

Demo: Open JavaScript Reference

<script type="text/javascript">

function maxopen(url, winattributes){
 var maxwindow=window.open(url, "", winattributes)
 try{ //try manipulating the window (in IE, if the domain opened is offsite, an exception is thrown)
  maxwindow.moveTo(0, 0) //first move window to upper left corner of screen
  maxwindow.resizeTo(screen.availWidth, screen.availHeight) //resize window to available screen size (minus taskbar etc)
 }
 catch(e){}
}

</script>

<a href="#" onClick="maxopen('index.shtml', 'resize=1, scrollbars=1, status=1'); return false">Open JavaScript Reference</a>

colorDepth The bit depth of the color palette available for displaying images in bits per pixel. Using this property, you can test for 8 bit screens for example, which are limited as far as the range of colors they can display"

<script type="text/javascript">

if (screen.colorDepth<=8) //if screen is 8 bit or less
 document.body.style.background="white url(8bitsafe.gif)" //simple background for 8 bit screens
else
 document.body.style.background="white url(fancy.gif)" //fancy background for modern screens.

</script>

pixelDepth

-Mozilla/Firefox specific property

Display screen color resolution (bits per pixel). Interchangeable with screen.colorDepth above in terms of value returned.
width The total width of the screen, in pixels.
height The total height of the screen, in pixels.

Reference List

Partners
Right column

CopyRight 1998-2012 JavaScript Kit. NO PART may be reproduced without author's permission.