• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 14. The Document Object > Document Color Properties

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint