File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes navigator.userAgent wrong IE version detection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "navigator.userAgent wrong IE version detection" Watch "navigator.userAgent wrong IE version detection" New topic

navigator.userAgent wrong IE version detection

Liwuen Chew

Joined: Mar 11, 2010
Posts: 24
Hope someone can help me with this. I'm running a JS function which uses the navigator.userAgent string to get the browser's main information (Among this there is the browser version).
My problem is that, for some reason, navigator.userAgent return version 7 as the actual version when the script is run in IE9. Tried with different browsers and all of them work fine, is just IE the one that is having detection issues.
Can you please help me onto getting the reason why it detects wrongly the IE version? Thanks in advance!
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Your browser is running in IE7 mode in IE9. It is right, your sniffing is wrong.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63874

Browser sniffing is generally regarded as a poor practice -- rather, features detection is preferred.

For what reason as you sniffing the browser?

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: navigator.userAgent wrong IE version detection
It's not a secret anymore!