?
Solved

Javascript test for Mozilla Firefox or Microsoft Internet Explorer IE

Posted on 2007-08-03
8
Medium Priority
?
6,037 Views
Last Modified: 2013-12-08
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
0
Comment
Question by:fibo
  • 4
  • 3
8 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 19626742
You can run both IE and Firefox side by side at the same time on the same machine.

hongjun
0
 
LVL 29

Author Comment

by:fibo
ID: 19626789
Thx, I know, I do.

But I really want to run a single program that will behave differently
0
 
LVL 33

Expert Comment

by:hongjun
ID: 19626810
>>But I really want to run a single program that will behave differently

Don't understand
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:SirCrofty
ID: 19626834
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
 
LVL 29

Author Comment

by:fibo
ID: 19627089
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
 
LVL 33

Accepted Solution

by:
hongjun earned 2000 total points
ID: 19627108
You can try this


if ( window.ActiveXObject ) {
    // IE
}
else {
  // Firefox
}
0
 
LVL 29

Author Comment

by:fibo
ID: 19627856
Great, exactly the simple solution I was looking for. Thx
0
 
LVL 33

Expert Comment

by:hongjun
ID: 19629508
Glad I could help and apologies in failing to understand your question earlier.

hongjun
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question