JavaScripts :: Miscellaneous :: Browser Sniffer.
Browser detection made easy. The scripts below will detect Internet Explorer 6, Netscape 6, Firefox, Safari 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:
<script>
<!--
alert(navigator.userAgent);
// -->
</script>
Use this script to determine browser type. Note that IE5 is also IE6
<script>
<!--
// Browser sniffer. Written by PerlScriptsJavaScripts.com
ua = navigator.userAgent.toLowerCase();
ie6 = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
nnf = (ua.indexOf("netscape") != -1 && ua.indexOf("gecko") != -1);
nni = (ua.indexOf("netscape") != -1 && ua.indexOf("msie") != -1);
nn6 = (ua.indexOf("netscape") != -1);
gek = (ua.indexOf("gecko") != -1);
ff1 = (ua.indexOf("firefox") != -1);
opr = (ua.indexOf("opera") != -1);
mac = (ua.indexOf("mac") != -1);
web = (ua.indexOf("webtv") != -1);
saf = (ua.indexOf("safari") != -1);
kon = (ua.indexOf("konqueror") != -1);
nn4 = (document.layers);
// -->
</script>
Use this code to perform actions based on browser type.
<script>
<!--
if(opr){ // do this
alert("You are using Opera");
}
if(ie6){ // do this
alert("You are using Internet Explorer 6 or higher");
}
if(nn6){ // do this
alert("You are using Netscape 6");
}
if(saf){ // do this
alert("You are using Safari");
}
if(ff1){ // do this
alert("You are using Firefox");
}
if(mac){ // do this
alert("You are using a Macintosh OS");
}
// -->
</script>
|