Jump to Real's How-to Main page

Detect browser type and version

<HTML>
<HEAD>
<SCRIPT LANGUAGE= "JavaScript">
function isNetscape(v) {
  /*
  ** Check if the browser is Netscape compatible
  **    v  version number
  ** returns  true if Netscape and version equals or greater
  */
  return isBrowser("Netscape", v);
  }

function isMicrosoft(v) {
  /*
  ** Check if the browser is Microsoft Internet Explorer compatible
  **    v  version number
  ** returns  true if MSIE and version equals or greater
  */
  return isBrowser("Microsoft", v);
  }

function isBrowser(b,v) {
  /*
  ** Check if the current browser is compatible
  **  b  browser name
  **  v  version number (if 0 don't check version)
  ** returns true if browser equals and version equals or greater
  */
  browserOk = false;
  versionOk = false;

  browserOk = (navigator.appName.indexOf(b) != -1);
  if (v == 0) versionOk = true;
  else  versionOk = (v <= parseInt(navigator.appVersion));
  return browserOk && versionOk;
  }
</SCRIPT></HEAD><BODY><FORM>
<INPUT TYPE="button" 
       VALUE="Test for Netscape 4" 
       onClick="alert(isBrowser('Netscape', 4));">
<INPUT TYPE="button" 
       VALUE="Test for IE3" 
       onClick="alert(isBrowser('Explorer', 0));">
</FORM></BODY></HTML>
For more complete script to detect browser version, check the Netscape site

Here a simple detection snippet :

var ns = (document.layers)? true: false
var ie = (document.all)? true: false
var b = (ns)? "Netscape": (ie) ?"Explorer" : " an out-dated browser!?!"
alert("You are using " + b)

If you find this article useful, consider making a small donation
to show your supportfor this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]