Webmaster

DHTML : Rollover Text
Contents ]
Sékine Coulibaly

Browser Detection

To be able to adapt our DHTML effects to the Document Object Model implemented differently by Internet Explorer and by Netscape, we first have to identify the version and name of the visitor's browser. And, depending on the results, we will use the relevant instructions to produce our DHTML effects.

To do this, we will call on JavaScript.

Add the following script to your page between the <HEAD> and </HEAD> tags.

<SCRIPT LANGUAGE="Javascript">

ie4 = ((navigator.appName == "Microsoft Internet Explorer") &&
       (parseInt(navigator.appVersion) >= 4 ))
ns4 = ((navigator.appName == "Netscape") &&
      (parseInt(navigator.appVersion) >= 4 ))

if (ns4) {
    layerRef="document.layers";
    styleRef="";
} else {
    layerRef="document.all";
    styleRef=".style";
}
</SCRIPT>

Note that the code part that varies from one browser to another is stored in the layerRef variable:

  • document.all[my_layer].style for Internet Explorer;

  • document.layers[my_layer] for Netscape.