For the sake of simplicity, the body of the page is very brief. When the mouse moves
over the image link, the code inside the
onMouseOver event handler is run. This code
travel) so that
it appears highlighted. The important part of this event handler is the if statement; it allows the
image to be highlighted only if browser is equal to "rollover", that is, the browser is capable of
handling dynamic images. (Don't worry about understanding how the rollover works right now; we'll
be discussing rollovers in detail in Chapter 7. For now, all you need to understand is how the
browser detection works.)
A much more common use of browser detection these days is for pages that use Dynamic HTML (DHTML), which has a number of dependencies on browser version. (We'll be discussing DHTML in more detail in Chapter 9 and Chapter 10.) If your page uses a single DHTML element that can easily be replaced by standard HTML for browsers that don't support DHTML, you might consider using browser detection around that element to handle different browsers. At a minimum, you need four different branches, for Netscape 6, for IE 4 and later, for Navigator 4, and for all earlier browser versions, as shown in Example 6-6.
Example 6-6: Simple browser detection for DHTML
After determining which browser is being used, this script provides locations for three different implementations of a DHTML element, plus a place to put the standard HTML replacement. As you can imagine, if you are integrating DHTML throughout your page design, supporting these four branches will quickly cause your pages to get quite messy. In that case, you should probably use a different technique for browser detection, like the single-frame method that is discussed in the next section.
Created: December 17, 2001
Revised: December 17, 2001