Quickly determine client browser types in JavaScript code
The document object model and ASP pages offer several ways to determine a client's browser 
type.  Most, however involve long parsing routines that search for specific substrings 
within a larger string. Fortunately, using JavaScript, there's a quick way
to determine if the client browser is either Netscape Navigator 4+ or Internet Explorer 4+. The 
basic idea is that you test for objects in the browser's DOM that don't exist in the other 
browser's DOM.  For example, IE 4.0 + browsers include the document.all
collection, while NN4.0 + browsers support the document.layers collection. If 
one of these objects is null, then your code can infer that the client is the other browser type. 
For example, the following script displays the boolean results of each test when
you load a Web page:
 
<script language="JavaScript">
var nav4 = !(document.layers == null)
var iex4 = !(document.all == null)
alert("Nav: " + nav4 + " IE4: " + iex4)
</script>
 
As you can see, the first expression sets the nav4 variable equal to the opposite 
of document.layers=null.  So, if you view this page in an IE 4+ browser, document.
layers is null, and the entire expression evaluates to false.
 


Active Server Index

Main Index

Search RD Techbase