Screen colorDepth Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Screen

Description

The colorDepth property returns the bit depth of the color palette for displaying images.

Return Value

A Number, representing the bit depth of the color palette for displaying images, in bits per pixel.

Possible values:

  • 1 bit per pixel
  • 4 bits per pixel
  • 8 bits per pixel
  • 15 bits per pixel
  • 16 bits per pixel
  • 24 bits per pixel
  • 32 bits per pixel
  • 48 bits per pixel

The following code shows how to get the bit depth of the color palette:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<script>

if (screen.colorDepth <= 8)/*  w  w w.java2 s.c  om*/
  //simple blue background color for 8 bit screens
  document.body.style.background = "#0000FF"
else
  //fancy blue background color for modern screens
  document.body.style.background = "#87CEFA"

</script>

</body>
</html>

Related Tutorials