browser detect : Java Glossary


browser detect
Introduction WhichBrowser
User Agent Mondernizr
JavaScript Desperately Seeking
Conditional-CSS Links
Conditional Comments


Purists will tell you that it is extremely wicked to attempt to determine which browser/version you are using. The list is endless. The code keeps breaking. The code stops working as soon an a new version or new browser is released. However, if you to give the user instructions on how to use his browser, e.g. how to configure security, import a certificate, how to turn on Java, how to create a bookmark, you pretty well have to make a wild guess at the browser and OS (Operating System) . Further, if you are trying to collect stats on which browsers are most popular visiting your site and thus need extra testing, you need to detect the browser.

User Agent

The most reliable source of this information in the user-agent field in the HTTP (Hypertext Transfer Protocol) header. Your server has access to this field, but not CSS (Cascading Style Sheets) or HTML (Hypertext Markup Language).


If you scour the net, you will find hundreds of code snippets that often work for a small set of browsers. Unfortunately, nobody ever bothers to provide a complete HTML example to show how to wrap this snippet is a sandwich of JavaScript and HTML to permit conditional display of text. The other problem is nobody deletes code snippets that no longer work. You pretty well have to learn JavaScript yourself to go this route.


Conditional-CSS requires you to install code your server than generates custom CSS depending or which browser each client is using. You write a unified CSS style sheet with conditionals in it that mark certain rules and only applying to certain browsers. It discovers the browser from the user-agent field in the HTTP header.

Conditional Comments

Microsoft discontinued support for conditional comments in version 10. Prior to that you could put magic comments in your code that most browsers would ignore, but that only IE could see and render. The net is full of obsolete advice on using this feature.


This scheme uses a combination of JavaScript in the client and PHP (Pre-Hypertext Processor) on the server. The server analyses the user-agent field in the HTTP header. The JavaScript loads a generated detectIE.js file containing the information it has gleaned. JavaScript uses the file to create a WhichBrowser object. JavaScript can then pick off its various fields.


Modernizr is a JavaScript library that will tell you a shitload of facts about your browser’s capabilities, but it refuses to tell you its name. Knowing this is wicked. You are supposed to code based on capabilities even when what you are doing has bugger all to do with capabilities.

Desperately Seeking

I have yet to find a sufficiently documented scheme that works when you do not have permission to run code on the server.

Here is what we need: There are thousands of people who do not know JavaScript, but are quite conversant in HTML and CSS . Everyone, who writes browser-detect or capabilities-detect software presumes their clients already know JavaScript. What we boobs need are a few examples of how to insert conditionality into HTML that does not require any server side code, just perhaps loading a JavaScript library into the client browser. Ideally the conditional blocks could be large and would not need any special escaping.

E.g. for IE users, I want to display:

For non-IE users I want to display:

Please show us everything we must embed in our HTML to make this work, including markup in the header and tail end to load JavaScript code.

I found this piece of code which looked like 90% of the solution:

Unfortunately, JavaScript programmers consider it too obvious to ever show you what you do with this JavaScript to conditionally show two variants of the text. I get the impression you are supposed to embed the two alternate texts as String literals embedded in a chunk of JavaScript. Yuch!

I have been learning JavaScript. I got detectIE to work, sort of.

Here is the solution:

First load the detectIE function.

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

Then generate either of the two alternate wordings.

I would hope there is a more elegant way of doing that is that does not mangle the wordings, but at least this works.

However, there is a catch 22. This code prompting the user to OK Active X does not run until the user has already granted permission for ActiveX to run. Phht! Further <noscript cannot be wrapped around a <li>…</li> the way <script can. JavaScript reeks of eau de kludge. The whole project is pointless! I had to remove all the JavaScript.

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number