Detect Browser in JavaScript

I know navigator.userAgent will return information on the browser, but if someone is using a FireFox plugin called IE Tab, https://addons.mozilla.org/en-US/firefox/addon/1419, the userAgent will return IE browser info.  Is there another way to detect the browser, or at least detect that the user is spoofing the browser?
LVL 6
jello024Asked:
Who is Participating?
 
jello024Author Commented:
b0l is right, document.all works in FF when IETab is active.
But, it looks like IETab uses the IE7 engine, so if I use a script to check for IE8 then that should work. So I've got 3 steps to validate the browser with JavaScript.
1. check the userAgent for MSIE 8.  This will take care of all non-IE8 browsers including FF with IETab.
2. check document.all.  This will take care of FF without IETabs, but with a userAgent spoof like Modify Headers.
3. For FF with IETabs and Modify Headers I found a script that works in IE8, but not any other version of IE:  document.querySelectorAll('.Class'). I can put it in a try/catch and look for an error. This looks good until IETabs is upgraded to emulate IE8.  I'll wait till tomorrow night to dish out some points just in case anyone else has a better idea.
0
 
HainKurtSr. System AnalystCommented:
thats the purpose of IE tab :) user-agent is the only thing. this addon is using IE com objects so it is same as IE, you cannot distunguish it...

FF 3.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)

FF IE Tab
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB6.3; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8)

IE8
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB6.3; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8)
0
 
b0lsc0ttIT ManagerCommented:
No.  That is just one reason browser detecting isn't a recommended practice.  Of course the specifics will depend on why you need to know this but it is better to test for an object, property, etc if that is why you are doing the test.  If you are doing this for a specific need then it may help if you share that; there may be a better way to do it.  If you were just asking about the reliability of using userAgent then the above is the answer.  You can't detect it being spoofed.

bol
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
jello024Author Commented:
My boss is a microsoft fanboy and he wants employees to only use IE on our intranet. That is easy to find out in our office, but we can't look at computers at our other branches.  We don't need details on the broswer, just whether or not it is IE. Maybe a script that doesn't run in firefox even with 'IE tabs'.
0
 
kadabaCommented:
>> thats the purpose of IE tab :) user-agent is the only thing. this addon is using IE com objects so it is same as IE, you cannot distunguish it...

As mentioned IE tab was introduced to emulate the IE browser.

 >> just whether or not it is IE.
You could always check if the browser is IE or not and that should end it there. If some other browser you might take appropriate action. If IE Tab is used it is as good as using IE then why the worry?


0
 
BadotzCommented:
var ie = false;
if (document.all) {
    ie = true;
}
0
 
HainKurtSr. System AnalystCommented:
IE tab in FF = IE

so dont worry, be happy...

also you can use this :

var nonIE = (!document.all);

in your JS...
0
 
BadotzCommented:
HainKurt: Thanks for repeating my suggestion.
0
 
b0lsc0ttIT ManagerCommented:
To be honest I haven't ever used IETab so I may be wrong but I don't believe document.all will be useful in this case.  Maybe I give IETab more credit than it deserves but I understand it does a great job of acting like IE in Firefox.  Even to the point of allowing ActiveX objects to run, which they normally wouldn't in non-IE browsers.  It is definitely an easy test and worth trying but I don't believe it will give the result you hope to get.

Let us know what happens though but if that behaves as if you used IE then I don't know of any IETab "limitation" that could be used to detect IE vs Firefox using the addon.

bol
0
 
BadotzCommented:
The only way to be realy sure is to connect to each user's workstaton and run an inventory of installed apps. Then, if IE is not installed, reprimand the Poor Soul who stares into the monitor all day long, doing your bidding, and ruin his/her day.

Draconian, perhaps, but effective.
0
 
b0lsc0ttIT ManagerCommented:
Thanks for posting to let us know.  I am glad you tried it and nice to confirm what I feared.

Of course #1 has the main limitation that it could still be spoofed.  However since your main desire here appears to be catching those using IETab it may not be a limitation you are willing to "live with."

As far as the #3 that is good to know.  I am sure IETab will eventually be updated (as long as the developer is still active).  Since it is so popular and useful I would imaging even if IETab dies there will be another to replace it.  So basically the steps have a limited life (and since IE 8 seems pretty good the "life" could be shorter).

Are those steps in order?  What is your logic in the code?  It seems that may be an area for improvement.  It has been a long, tiring day for me though so I will hold off "judging" that until I am rested.

Just some thoughts about the steps although I will understand if you still feel it worth proceeding.  Let us know if you have any other questions.

bol
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.