Screen colorDepthProperty

Screen 对象参考手册Screen Object

Definition and Usage

The colorDepth property returns the bit depth of the palette on the target device or buffer.

Syntax

screen.colorDepth


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the colorDepth property.


Examples

Example 1

Return the bit depth of the palette:

<script>

document.write("Color depth: " + screen.colorDepth);

</script>

The output result of the above example:


Try it yourself »

Example 2

Display alternating background colors on an 8-bit screen:

if (screen.colorDepth<=8)
// Simple blue background for 8-bit screens
    document.body.style.background="#0000FF"
else
// Fancy blue background for modern screens
    document.body.style.background="#87CEFA"

Try it yourself »


实例

More Examples

This example contains all screen properties.


Screen 对象参考手册Screen Object Other Extensions