Java Reference
In-Depth Information
The document object has a number of properties associated with it, which are also array‐like
structures called collections . The main collections are the forms , images , and links collections.
Internet Explorer supports a number of other collection properties, such as the all collection
property, which is an array of all the elements represented by objects in the page. However, you'll
concentrate on using objects that have standard cross‐browser support, so that you are not limiting
your web pages to just one browser.
You look at the images and links collections shortly. A third collection, the forms collection, is
one of the topics of Chapter 11 when you look at forms in web browsers. First, though, you look at
a nice, simple example of how to use the document object's methods and properties.
using the document object
You've already come across some of the document object's properties and methods—for example,
the write() method and the bgColor property.
trY it out Setting Colors according to the User's Screen Color Depth
In this example, you set the background color of the page according to how many colors the user's
screen supports. This is termed screen color depth . If the user has a display that supports just two colors
(black and white), there's no point in you setting the background color to bright red. You accommodate
different depths by using JavaScript to set a color the user can actually see.
<!DOCTYPE html>
 
<html lang="en">
<head>
<title>Chapter 8, Example 2</title>
</head>
<body>
<script>
var colorDepth = window.screen.colorDepth;
 
switch (colorDepth) {
case 1:
case 4:
document.bgColor = "white";
break;
case 8:
case 15:
case 16:
document.bgColor = "blue";
break;
case 24:
case 32:
document.bgColor = "skyblue";
break;
default:
document.bgColor = "white";
 
Search WWH ::




Custom Search