|
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 JavaScriptwhich is only the case in Netscape 3.0 and later. A script to swap one image for another might look like this: |