[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Detect Browser in JavaScript

Posted on 2009-12-16
11
Medium Priority
?
411 Views
Last Modified: 2012-05-08
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?
0
Comment
Question by:jello024
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 61

Assisted Solution

by:HainKurt
HainKurt earned 1000 total points
ID: 26068221
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
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 1000 total points
ID: 26068236
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
 
LVL 6

Author Comment

by:jello024
ID: 26068310
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
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.

 
LVL 22

Expert Comment

by:kadaba
ID: 26068865
>> 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
 
LVL 29

Expert Comment

by:Badotz
ID: 26069980
var ie = false;
if (document.all) {
    ie = true;
}
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26073073
IE tab in FF = IE

so dont worry, be happy...

also you can use this :

var nonIE = (!document.all);

in your JS...
0
 
LVL 29

Expert Comment

by:Badotz
ID: 26073270
HainKurt: Thanks for repeating my suggestion.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 26076516
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
 
LVL 6

Accepted Solution

by:
jello024 earned 0 total points
ID: 26076649
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
 
LVL 29

Expert Comment

by:Badotz
ID: 26076716
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 26076955
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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