Accessibility
 
Home > Products > Dreamweaver > Support > Editing HTML in Dreamweaver
Dreamweaver Icon Macromedia Dreamweaver Support Center - Editing HTML in Dreamweaver
Checking for browser brand and version number

If you want to give one page to users of Internet Explorer 4 and Navigator 4, and another page to all other users, you could write the following JavaScript:

<SCRIPT LANGUAGE="JavaScript">
if (navigator.appVersion.indexOf('4.0') != -1) {
window.location = 'dhtml_page.html';
}
else{
window.location = "regular_page.html";
}
</SCRIPT>

The preceding script looks for the position of '4.0' in the navigator.appVersion string. If it doesn't find '4.0,' it reports the position as -1. Therefore, saying "if the position is not -1" is the same as saying "if the text '4.0' exists somewhere in the appVersion string."

You may also need to check for a specific browser because of differences in JavaScript support. For example, the Rollover Buttons technique (accessible from the Dreamweaver HTML Help Pages) depends on the src property of the image object being accessible to JavaScript––which is only the case in Netscape 3.0 and later. A script to swap one image for another might look like this:

<SCRIPT LANGUAGE="JavaScript">
function swapImage(){
if (navigator.appName == 'Netscape' && parseFloat(navigator.appVersion) >= 3) {
document.imageName.src = 'newSrc';
}
}
</SCRIPT>
Notice that there are two equal signs in the check for appName . In JavaScript, you use one equal sign to set the value of a variable or property (as in window.location.href = "dhtml_page.html") and two equal signs to check the value of a variable or property. The spaces on either side of the equal sign are optional; many developers use them to make their code more readable.

The parseFloat() built-in JavaScript function converts a string to a number. For example, if the user is browsing with Netscape Navigator 4 on Windows 95, parseFloat() converts the string 4.01 [en] (Win95; I) to the number 4.01. Since the appName in this case is Netscape, and 4.01 is greater than 3, Navigator 4 passes the test presented in swapImage() .

The && indicates that the browser must match both criteria to pass the test. Thus, Netscape Navigator 2.02 would fail because its appVersion is not greater than or equal to 3. Internet Explorer (IE) 3 would fail the test on both counts: its appName is Microsoft Internet Explorer, and its appVersion parses to 2.0 (IE 3 reports its version as 2.0 because that is the Navigator version it most closely resembles).

To Table of Contents Forward to next document