Java Reference
In-Depth Information
act on that information and make sure users are directed to pages that will work with their browsers.
The last section in this chapter is dedicated to this important subject, so we will not discuss it further here.
The screen Object
The screen object property of the window object contains a lot of information about the display capabili-
ties of the client machine. Its properties include the height and width properties, which indicate the
vertical and horizontal range of the screen, respectively, in pixels.
Another property of the screen object, which you will be using in an example later, is the colorDepth
property. This tells you the number of bits used for colors on the client's screen.
The document Object
Along with the window object, the document object is probably one of the most important and com-
monly used objects in the BOM. Via this object you can gain access to the HTML elements, their proper-
ties and methods inside your page.
Unfortunately, it's here, at the document object, that browsers can differ greatly. This chapter concen-
trates on the properties and methods that are common to all browsers. More advanced manipulation of
the document object will appear in Chapter 12.
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. IE 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 be concentrating on using objects that
have cross-browser support, so that you are not limiting your web pages to just one browser.
You'll be looking at the images and links collections shortly. A third collection, the forms collection,
will be one of the topics of the next chapter when you look at forms in web browsers. First, though,
you'll 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 PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
Search WWH ::




Custom Search