Ok, I know that it is standard practice to "sniff" out a browser, but this isn't what you really wanted to do! What you really want to know is whether or not the user's current browser is compatible with your script. It could be any browser as long as it supports the functionality your script requires.
So, the question shouldn't be: Is this IE or is this NS/FF?
Ask instead: Does this browser have document.attachEvent function or a document.addEventListener function?
(if you are using those functions, that is)
If you test for functionality you can avoid the trap of sniffing the user agent string. Besides, FF has a plugin that allows you to change the UA to match IE which fools those kind of scripts and breaks the page.
In the head section of your page:
Code:
<head>
<script type="text/javascript"><!--
var scriptStr = 'unknown.js';
if (typeof document.attachEvent != 'undefined') scriptStr = 'ie_compatible.js';
if (typeof document.addEventListener != 'undefined') scriptStr = 'ns_compatible.js';
document.write('<scr'+'ipt type="text/javascript" src="'+scriptStr+'"></script>');
/* Do not put any code here that relys on
either of the three scripts mentioned above. */
//-->
</script>
<!-- One of the above scripts will be loaded here -->
<script type="text/javascript"><!--
/* Now you can use code that depends on
any of the three scripts mentioned previously. */
//defined in one of the scripts (unkown.js, ie_compatible.js or ns_compatible.js)
BrowserIndependent.attachListener(myElement, myFunct, true);
//--></script>
</head>
Change: document.attachEvent and document.addEventListener to the functions required by the scripts they load.