Detecting which browser the visitors to your site are using is useful for statistical purposes in helping you to work out which older browsers are worth the wextra effort of continuing to support. By this I mean where you take extra steps to try to work around those standards that a given browser doesn't support so as to have that older browser behave as close as possible to the way that more modern browsers behave in how they display your page. You should of course continue to support even older browsers to the extent that your page content is still readable even in the earliest of browsers.
So how do we detect which browser our visitors are using? Well the easiest way is probably to look at the useragent that the browser supplies. Now this field can be changed by the browser owner to contain just about anything at all but the majority of our visitors will leave the value set to its default value where it does actually identify which browser it is that they are using rather than misidentifying itself as a different browser in order to bypass badly written code that ignores certain browsers. There will be a percentage of browsers configured to identify themselves as a different browser but provided that we are only using the information for statistical purposes we can reasonably assume that the figures we get for the usage of the different browsers are within say 10% of the correct figure. This is accurate enough for determining those browsers where you have sufficient visitors using the browser to make it worthwile to put in the extra effort in getting the page fully functional.
var browser = 'Not IE or Opera';
@if (@_jscript) browser = 'Internet Explorer';
if (window.opera) browser = 'Opera';
/* @end @*/
This article written by Stephen Chapman, Felgall Pty Ltd.