Browser detection with javascript

In a perfect world, all the major browsers would co-exist happily together, supporting the same set of objects and features. But then again, in that world, I’d be on an island enjoying the sun.

Before we reach that place, this tutorial looks at how to detect support for a particular JavaScript property or method before attempting to invoke it. It serves as an alternate, in many cases, superior way to strict browser detection for creating cross browser friendly scripts.

Here is an small example of how to detect the browser & version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
<body>
 
<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
 
document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
</script>
 
</body>
</html>

Another (more practical) way to discriminate the browser can be done like this:

1
2
3
4
5
6
7
  var browser=navigator.appName;
  if (browser=="Netscape"){
       // mozilla, netscape, chrome, ...
  }
  else if (browser=="Microsoft Internet Explorer"){
       // Internet Explorer 4 or Opera with IE user agent
  }

Have fun ;)

Related posts:

  1. DeepZoom & SEADragon (IV)
  2. Javascript – sort tables (by column values) [easy and opensource]
  3. Spoiler div con HTML and Javascript
  4. W3C validator issues with ampersand (&) in javascript location.href
  5. Javascript: depurando errores

One Response to “Browser detection with javascript”

Leave a Reply

Paypal donate

Please help me keep this blog up by donating.

Por favor, ayúdame a continuar con el blog donando.