|
JavaScript Programs Detecting the User's Browser
This page contains a script that checks the user's browser name and browser version and displays that data in a dialog box each time you load the page. Here's the script:
<SCRIPT LANGUAGE = "JavaScript">
<!--
var browserName = navigator.appName
var browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape")
{
alert("Welcome Netscape Navigator user!" + "\n\n" + "You are using version " + browserVer)
}
else if (browserName == "Microsoft Internet Explorer")
{
var ver = navigator.appVersion
var start = ver.indexOf("MSIE") + 5
var end = ver.indexOf(";",start)
browserVer = parseInt(ver.substring(start,end))
alert("Welcome Internet Explorer user!" + "\n\n" + "You are using version " + browserVer)
}
else
{
alert("Welcome " + browserName + " user!" + "\n\n" + "You are using version " + browserVer)
}
//-->
</SCRIPT>
To use this script, copy everything between and including the <SCRIPT>
and </SCRIPT> tags and insert it on your page between the
</HEAD> and <BODY> tags. Note that you'll probably want to replace the not-very-useful
alert messages with something more interesting. (For example, see my
Mouseover III script.)
If you want to know the exact strings that are returned by the navigator.appName and navigator.appVersion function, see the Browser II page. Copyright © 1995-2008 Paul McFedries and Logophilia Limited |