DekGenius.com
Team LiB   Previous Section   Next Section

14.3 Document Color Properties

The bgColor , fgColor, linkColor, alinkColor, and vlinkColor properties of the Document object specify foreground, background, and link colors for the document. They are read/write properties, but they can be set only before the <body> tag is parsed. You can set them dynamically with JavaScript code in the <head> section of a document, or you can set them statically as attributes of the <body> tag, but you cannot set them elsewhere. The exception to this rule is the bgColor property. In many browsers, you can set this property at any time; doing so causes the background color of the browser window to change.[2] Other than bgColor, the color properties of the Document object merely expose attributes of the <body> tag and are basically uninteresting.

[2] There is a bug in Netscape 3 on Unix platforms such that changing the background color can make the contents of the page disappear (usually until the window is scrolled or otherwise redrawn). In Netscape 6, you can set the bgColor only once; any additional settings are ignored.

Each of these color properties has a string value. To set a color, you can use one of the predefined HTML color names, or you can specify the color as red, green, and blue color values, expressed as a string of six hexadecimal digits in the form #RRGGBB. You may recall that Example 13-7 set the bgcolor attribute of the <body> tag to a color string expressed in this fashion.

In the W3C DOM standard, the color properties of the Document object are deprecated in favor of properties of the Element object that represents the <body> tag. Furthermore, the HTML 4 standard deprecates the color attributes of the <body> tag in favor of CSS style sheets. What this means is that you probably should not write scripts that rely heavily on these doubly deprecated color properties!

    Team LiB   Previous Section   Next Section