provided by: 
Originally published at Internet.com ...use these to jump around or read it all
[How'd You Do That?] [The Script] [Deconstructing the Script] [A Better Example]
[Where's the Code?] [Getting Specific] [Setting Your Page as Home Page: IE5.0 only!]
It use to be that the favored method of posting elements that dealt with specific browsers was to use a Browser Detector JavaScript . Then that script would send people to a whole separate page created just for their browser. But that meant making a bunch of different pages. Here I'm going to show you a method of putting that browser choice right on your page. A JavaScript will read the user's browser and, depending on what that person is running, post text and code to the page.
Now it will be possible to have both DHTML and Layer commands on the same page. Depending on whether the user is running IE or Navigator, they'll get the correct code for their system.
Here...let me take a shot at it. Are you Yeah? Thought so.
-----------------------------------
How'd You Do That?
I did it through a JavaScript that first tests your browser's make and then tests your browser's version. Depending on the browser version and make I posted the text "running XXXX.x or better?". I just stuck the text "Are you" in front so the JavaScript text would make a sentence.
But this is using the script in it's easiest form. You can do so much more than a simple parlor trick. But first let's find out how I got the text to display correctly.
-----------------------------------
The Script
I'll show it to you in a second. First off, let me tell you the thinking behind it.
There are so many different browsers and versions of browsers that to test for them all individually would be silly. You would do nothing but constantly update your scripts every time a new version comes out. So you need to make some broad, general statements. Here's what I test for in this script:
* Is the browser Netscape, IE or neither? * Is the browser version at least 4.0?
I made the second condition because it seems to be that browser version 4.0 were the turning point for both Netscape Navigator and Internet Explorer. Version 4.0 is when layers came to Netscape and when DHTML came to IE. That seemed like a solid cut off point as you can safely assume that all versions above 4.0 will continue to support what 4.0 does. Remember I'm giving you just the basic format here first.
Enough description!
Here's the Script That Did the Trick
-----------------------------------
Deconstructing the Script
I'lll hit is step by step. After the first little blurb of code, you'll pretty much be able to take it the rest of the way, but here we go.
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0")
{document.write("Running IE 4 or better?")}
The script is a series of IF statements that test the browser name and version. Read along in the code above as I follow it through its test.
* if starts the command. The code the follows in the parentheses sets the test.
* navigator.appName is JavaScript for the name of the browser.
* == Those double equal signs mean "is equal to".
* The two names are "Netscape" and "Microsoft Internet Explorer" notice the capitalization and double quotes. You have to have it just like this.
* && is JavaScript for "and". Thus we're test two elements here, the name of the browser and then what follows.
* navigator.appVersion is JavaScript for the browser's version number. Now, we'll get into this a little more later in the tutorial, but version numbers get tricky. However, as long you denote version in the "#.#" format in double quotes as I have above, you can make very broad statements like is the browser 4.0 or better.
* >= means greater than or equal to. (<= means less than or equal to. You'll see that coming up).
* "4.0" is my 4.0 cut off point for version 4.0 browsers.
What follows within the curly brackets is what happens if the condition is met. In this case a "document.write" statement is used to write text to the page. That's what document.write does. It simply writes what is within the double quotes to the page, no questions asked. Just make sure to have double quotes because without them the script will think that the text refers to a command rather than simple text to be printed. Error.
In each of the following cases, I have text the denotes the browser version being printed to the page.
The next bit of code tests is the browser is IE and if it is less than version 4.0:
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion < "4.0")
{document.write("Running IE 3.x or less?")}
Next we test for Netscape browser and version 4.0 or better:
if (navigator.appName == "Netscape" && navigator.appVersion >= "4.0")
{document.write("Running Netscape 4 or better?")}
Navigator and versions less than 4.0:
if (navigator.appName == "Netscape" && navigator.appVersion < "4.0")
{document.write("Running Netscape 3.x or under?")}
Finally, we test to see if the user has neither Netscape nor Internet Explorer. "!=" means "is not equal to".
if (navigator.appName != "Microsoft Internet Explorer" && navigator.appName != "Netscape")
{document.write("not running IE or Netscape?")}
At least one of the conditions will be true and something will get written to the screen.
Notice that when I first had you look at the script that the first line of code (the "if" lines) were all on one line. Make sure your code is like that. If not...error.
-----------------------------------
A Better Example
Granted, this does take a little bit of coding to get through. But once you get the effect, you'll want to start using this stuff all over your pages to take advantage of what one browser will do that another won't...all while not leaving earlier version browsers out of the loop.
Author: Joe Burns
Read article at Internet.com site