Browser sniffing is a technique used in websites and web applications in order to determine the web browser a visitor is using, and to serve browser-appropriate content to the visitor. This practice is sometimes utilized to circumvent incompatibilities between browsers due to misinterpretation of HTML, Cascading Style Sheets (CSS), or the Document Object Model (DOM). While the World Wide Web Consortium maintains up-to-date central versions of some of the most important Web standards in the form of recommendations, in practice no software developer has designed a browser which adheres exactly to these standards; implementation of other standards and protocols, such as SVG and XMLHttpRequest, varies as well. As a result, different browsers display the same page differently, and so browser sniffing was developed to detect the web browser in order to help ensure consistent display of content.
It's also used to detect mobile browsers and send them mobile-optimized websites.
var isIE = window.ActiveXObject ? true : false;
This code is run by the client computer, and the results are used by other code to make necessary adjustments on client-side. In this example, the client computer is asked to determine whether the browser can use a feature called ActiveX. Since this feature was proprietary to Microsoft, a positive result will indicate that the client may be running Microsoft's Internet Explorer. This is no longer a reliable indicator since Microsoft's open-source release of the ActiveX code, however, meaning that it can be used by any browser.
Client-side sniffing makes use of features on the client computer. These features must be available and active in order for the process to work. However, since the web server has no control over whether the client actually has the features available, client-side sniffing is unreliable. It is possible, however, to determine many features of the browser without depending on the client configuration. The web server communicates with the client using a communication protocol known as HTTP, or Hypertext Transfer Protocol. Information communicated between client and server usually includes information about the browser being used to view the web site. See user agent for more details on this.
Issues and standards