Java Reference
In-Depth Information
You don't need to set a different color for each colorDepth possible, because many of them are simi-
lar when it comes to general web use. Instead, you set the same background color for different, but similar,
colorDepth values. For a colorDepth of 1 or 4, you set the background to white. You do this by declaring
the case 1: statement, but you don't give it any code. If the colorDepth matches this case statement, it
will fall through to the case 4: statement below, where you do set the background color to white. You
then call a break statement, so that the case matching will not fall any further through the switch
statement.
{
case 1:
case 4:
document.bgColor = “white”;
break;
You do the same with colorDepth values of 8 , 15 , and 16 , setting the background color to blue as
follows:
case 8:
case 15:
case 16:
document.bgColor = “blue”;
break;
Finally, you do the same for colorDepth values of 24 and 32, setting the background color to sky blue.
case 24:
case 32:
document.bgColor = “skyblue”;
break;
You end the switch statement with a default case, just in case the other case statements did not
match. In this default case, you again set the background color to white.
default:
document.bgColor = “white”;
}
In the next bit of script, you use the document object's write() method, something you've been using
in these examples for a while now. You use it to write to the document — that is, the page — the num-
ber of bits the color depth is currently set at, as follows:
document.write(“Your screen supports “ + window.screen.colorDepth +
“bit color”)
You've already been using the document object in the examples throughout the topic so far. You used
its bgColor property in Chapter 1 to change the background color of the page, and you've also made
good use of its write() method in the examples to write HTML and text out to the page.
Now let's look at some of the slightly more complex properties of the document object. These properties
have in common the fact that they all contain collections. The fi rst one you look at is a collection con-
taining an object for each image in the page.
Search WWH ::




Custom Search