Browser detection made easy. The scripts below will detect Internet Explorer 4 and 5, Netscape 4 and 6 pre version 4 browsers and the Macintosh Platform, using the document's objects. Because Opera users can set their browser to be identified as Internet Explorer, Netscape or Opera, this script reads the UserAgent object and looks for the string "Opera". If the string "Opera" is not found in the UserAgent object, a negative one (-1) is returned. If the string is found, the character position of the string is returned. i.e. a number greater than or equal to zero (0), as zero is the position of the first character. To see what the UserAgent object returns, use this case sensitive code:
Use this code to perform actions based on browser type.
<script>
<!--
if(op){ // do this
alert("You are using Opera");
}
if(ie4){ // do this
alert("You are using Internet Explorer 4");
}
if(ie5){ // do this
alert("You are using Internet Explorer 5 or higher");
}
if(nn4){ // do this
alert("You are using Netscape 4");
}
if(nn6){ // do this
alert("You are using Netscape 6");
}
if(aol){ // do this
alert("You are using an AOL browser");
}
if(v3){ // do this
alert("You are using a pre version 4 browser");
}
// -->
</script>