Javascript test for Mozilla Firefox or Microsoft Internet Explorer IE

This is probably a great classic... but I can't find where it is here...

Working with javascript, I need to know if the page is running under Internet Explorer or Firefox: I will then load scripts and libraries accordingly.

It is just some dumb debugging code that will differ between versions, I do not need a 200% bulletproff solution
LVL 29
Bernard S.CTOAsked:
Who is Participating?
 
hongjunConnect With a Mentor Commented:
You can try this


if ( window.ActiveXObject ) {
    // IE
}
else {
  // Firefox
}
0
 
hongjunCommented:
You can run both IE and Firefox side by side at the same time on the same machine.

hongjun
0
 
Bernard S.CTOAuthor Commented:
Thx, I know, I do.

But I really want to run a single program that will behave differently
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
hongjunCommented:
>>But I really want to run a single program that will behave differently

Don't understand
0
 
SirCroftyCommented:
are you looking for something like this?

http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

Usually you can check certain javascript element properties in your script to see if they exist which allows you to determine which methods/properties to use, instead of doing actual browser sniffing from the get go, which can unreliable when new versions are released
0
 
Bernard S.CTOAuthor Commented:
in my case, I just want to test if
     var fso = new ActiveXObject('Scripting.FileSystemObject');
is possible, which would allow me (under IE) to write some debug information to a file.
(Under Firefox, this just explodes but I can use more powerful debugging tools).
I simply don't want to edit 1 jd file an 1 html file every time I switch browser while debugging.

I have been trying to test if 'ActiveXObject' exists, but my test, most probably badly written, did fail.
0
 
Bernard S.CTOAuthor Commented:
Great, exactly the simple solution I was looking for. Thx
0
 
hongjunCommented:
Glad I could help and apologies in failing to understand your question earlier.

hongjun
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.