0

I have a small JavaScript function that is supposed to return the IE version.

Problem is, when I publish and view the site this function is returning 7.

I am viewing the site with IE 8.0.7600.16385.

What's going on?

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}
4
  • Try calling alert(navigator.userAgent) to see what the page is getting.
    – josh.trow
    Jul 8, 2011 at 18:12
  • @rockerest lol awesome +1 for comment. I really think that might be it. MSIE is constantly screwing with the version in my experience. Jul 8, 2011 at 18:13
  • What does navigator.userAgent contain?
    – kba
    Jul 8, 2011 at 18:13
  • When I run IE9 in compatibility mode and alert navigator.userAgent it reports IE 8. gotta be compatibility mode.
    – rockerest
    Jul 8, 2011 at 18:16

1 Answer 1

4

Maybe your browser is running in IE 7 compatible mode?

3
  • If you haven't declared a DOCTYPE it will default to "quirks" or compatibility mode. Generally there will be a little "broken page" icon to the right of the URL bar.
    – rockerest
    Jul 8, 2011 at 18:12
  • there is a button next to the location bar Jul 8, 2011 at 18:12
  • alert(document.documentMode) will return the parser version currently running, as set by you, or by the user, or by some third party.
    – kennebec
    Jul 8, 2011 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.