user detection
user detection Abstract: This week’s article is rather late. We will study an example that will cover browser detection and other user related information via JavaScript. A limited information on this is already available in one of my earlier articles, but this one will go further. Navigator Object: JavaScript has several built-in objects. One of them, window covers the browser’s window. Another, navigator, represents the browser itself. Several properties of this object are available.
  • appName is used to get the browser’s name, such as Netscape.
  • codeName represents the code name, such as Mozilla.
  • appVersion is used to get the application version. Usually a substring (first four characters) represent the normal application version.
  • platform returns the operating system on which the browser is running, such as Win32.
Some functions also help us. The object navigator supports a method, javaEnabled, that returns a true / false value. As the name suggests, we can tell whether the browser supports Java or not by seeing the returned value. Screen: Detecting screen resolution can be very helpful in redirecting a user to a different page, depending upon the graphics used on a site. Screen resolution can be checked by screen.width and screen.height. Working Example: Copy and paste the following code in an empty Notepad window (or any other text editor), save it by giving it a .html extention and open it in your web browser.
<html>
<head>
<script language="JavaScript">
<!--
function showInfo ()
{
var appVersion = navigator.appVersion;
var version = appVersion.substring(0,4);
document.write("<center><table border=1 cellpadding=2><tr><td>");
document.write("<center><b>", navigator.appName,"</b>");
document.write("</td></tr><tr><td>");

document.write("<center><table border=1 cellpadding=2><tr>");
document.write("<td>Code Name: </td><td><center>");
document.write("<b>", navigator.appCodeName,"</td></tr>");
document.write("<tr><td>Version: </td><td><center>");
document.write("<b>",version,"</td></tr>");
document.write("<tr><td>Platform: </td><td><center>");
document.write("<b>", navigator.platform,"</td></tr>");

document.write("<tr><td>Java enabled: </td><td><center><b>");
if (navigator.javaEnabled()) document.write("Yes</td></tr>");
else document.write("No</td></tr>")

document.write("<tr><td>Screen Resolution: </td><td><center>");
document.write("<b>",screen.width," x ",screen.height,"</td></tr>");
document.write("</table></tr></td></table></center>"); }
//-->
</script>
</head>

<body onLoad="showInfo()">
</body>
</html>