Usage

The package you download contains two examples: one for client-side usage (demo.html) and one for server-side usage in ASP (demo.asp).

Requirements

The Javascript Browser Sniffer makes an extensive use of regular expressions and the search() and match() functions.

You will need Javascript 1.2 or greater for jsbrwsniff to work. Some examples:

Client-side usage

JsBrwSniff is easy to use. You only have to load the brwsniff.js file:

<script type="text/javascript" src="js/brwsniff.js"></script>

Then you can use it this way:

<script type="text/javascript">
  var br=new Array(4);
  var os=new Array(2);
  var flash=new Array(2);
  br=getBrowser();
  os=getOS();
  flash=hasFlashPlugin();
  document.write("Browser identifier: "+br[0]+"<br />");
  document.write("Browser version: "+br[1]+"<br />");
  document.write("Browser major version: "+getMajorVersion(br[1])+"<br />");
  document.write("Browser minor version: "+getMinorVersion(br[1])+"<br />");
  document.write("Browser engine: "+br[2]+"<br />");
  document.write("Browser engine version: "+br[3]+"<br />");
  document.write("Full user agent string: "+getFullUAString()+"<br />");
  document.write("Operating system identifier: "+os[0]+"<br />");
  document.write("Operating system version: "+os[1]+"<br />");
  document.write("Is Flash installed? " + (flash[0]==2 ? "Yes" : (flash[0] == 1 ? "No" : "unknown")) + "<br />");
  document.write("Flash version: "+flash[1]+"<br />");
</script>

For client-side usage, you do not need to feed getBrowser(), getOS() and getFullUAString() with any parameter.

Server-side usage

Since version 0.5, JsBrwSniff can also be used on the server-side. You only have to feed it with the variable that contains the user agent string. The following one is an example in ASP.

This goes in the <head> section of the document:

<script language="javascript" runat="server" src="brwsniff.js">
<script language="javascript" runat="server">
  function showBrwInfo() {
    var br=new Array(4);
    var os=new Array(2);
    var nav;
    nav='' + Request.ServerVariables("HTTP_USER_AGENT");
    nav=nav.toLowerCase();
    os=getOS(nav);
    br=getBrowser(nav);
    Response.write("Browser identifier: " + br[0] + "<br />");
    Response.write("Browser version: "+br[1]+"<br />");
    Response.write("Browser major version: "+getMajorVersion(br[1])+"<br />");
    Response.write("Browser minor version: "+getMinorVersion(br[1])+"<br />");
    Response.write("Browser engine: "+br[2]+"<br />");
    Response.write("Browser engine version: "+br[3]+"<br />");
    Response.write("Full user agent string: "+getFullUAString(nav)+"<br />");
    Response.write("Operating system identifier: " + os[0] +"<br />");
    Response.write("Operating system version: "+ os[1]);
  }
</script>

Now you can add this to the <body> of the document:

<%call showBrwInfo() %>

For server-side usage, you DO need to feed getBrowser(), getOS() and getFullUAString() with the user-string parameter.

Please note that you can only perform Flash plug-in detection on the client-side. It will NOT work on the server-side.

Although you can use the getFullUAString(nav) function on the server-side, it's useless: it will return nav.

Browser identifiers

Since version 0.3.5, JsBrwSniff returns an array of four strings:

Operating system identifers

Since version 0.4.0, operating system is returned as an array of two values: first value is OS short identifier and second value is OS version.

Browser engine identifiers

Bot identifiers

Please note that:

Javascript version

Since version 0.5.3, function jsVersion() returns the highest version of the Javascript language the browser *claims* to support.

Please note this is not reliable information, as different browsers may implement different objects or implement fake objects (i. e. checking for the existence of the object will return true, doing something with it would do nothing).

Pop-up blocker detection

To find out if the client has a pop-up blocker installed, jsbrwsniff tries to open a 1x1 window using the popupsAllowed() function.

When using this information, please note popups may be allowed for one site but disabled for another. It is therefore very important the code from which you open your popups and the jsbrwsniff.js file be on the same site or subsite (subdirectories -mysite.com/js/- are fine, subsites -js.mysite.com- are not).

Other functions