Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:50:44+00:00 2026-05-24T06:50:44+00:00

I have some javascript that gets the browser name and version number of the

  • 0

I have some javascript that gets the browser name and version number of the browser. Everything works fine; I get the correct name and versions correctly, unless it’s a specific site. On that specific site, instead of my IE9 showing version 9, version 8 is shown. If I test in other browsers, again, the name and versions are correct. The problem is just within IE. It’s not just IE9 either; IE8 on that specific site shows version 7. I’ve also just made a separate HTML page with just the javascript and I get the correct version numbers. The code is as follows:

<html>
    <head>

        <script type="text/javascript">
    var BrowserDetect = {
            init: function () {
                this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
                this.version = this.searchVersion(navigator.userAgent)
                    || this.searchVersion(navigator.appVersion)
                    || "an unknown version";
                this.OS = this.searchString(this.dataOS) || "an unknown OS";
            },
            searchString: function (data) {
                for (var i=0;i<data.length;i++) {
                    var dataString = data[i].string;
                    var dataProp = data[i].prop;
                    this.versionSearchString = data[i].versionSearch || data[i].identity;
                    if (dataString) {
                        if (dataString.indexOf(data[i].subString) != -1)
                            return data[i].identity;
                    }
                    else if (dataProp)
                        return data[i].identity;
                }
            },
            searchVersion: function (dataString) {
                alert("this.versionSearchString: " + this.versionSearchString);
                alert("useragent: " + dataString);
                var index = dataString.indexOf(this.versionSearchString);
                if (index == -1) return;
                return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
            },
            dataBrowser: [
                {
                    string: navigator.userAgent,
                    subString: "Chrome",
                    identity: "Chrome"
                },
                {   string: navigator.userAgent,
                    subString: "OmniWeb",
                    versionSearch: "OmniWeb/",
                    identity: "OmniWeb"
                },
                {
                    string: navigator.vendor,
                    subString: "Apple",
                    identity: "Safari",
                    versionSearch: "Version"
                },
                {
                    prop: window.opera,
                    identity: "Opera"
                },
                {
                    string: navigator.vendor,
                    subString: "iCab",
                    identity: "iCab"
                },
                {
                    string: navigator.vendor,
                    subString: "KDE",
                    identity: "Konqueror"
                },
                {
                    string: navigator.userAgent,
                    subString: "Firefox",
                    identity: "Firefox"
                },
                {
                    string: navigator.vendor,
                    subString: "Camino",
                    identity: "Camino"
                },
                {       // for newer Netscapes (6+)
                    string: navigator.userAgent,
                    subString: "Netscape",
                    identity: "Netscape"
                },
                {
                    string: navigator.userAgent,
                    subString: "MSIE",
                    identity: "Explorer",
                    versionSearch: "MSIE"
                },
                {
                    string: navigator.userAgent,
                    subString: "Gecko",
                    identity: "Mozilla",
                    versionSearch: "rv"
                },
                {       // for older Netscapes (4-)
                    string: navigator.userAgent,
                    subString: "Mozilla",
                    identity: "Netscape",
                    versionSearch: "Mozilla"
                }
            ],
            dataOS : [
                {
                    string: navigator.platform,
                    subString: "Win",
                    identity: "Windows"
                },
                {
                    string: navigator.platform,
                    subString: "Mac",
                    identity: "Mac"
                },
                {
                       string: navigator.userAgent,
                       subString: "iPhone",
                       identity: "iPhone/iPod"
                },
                {
                    string: navigator.platform,
                    subString: "Linux",
                    identity: "Linux"
                }
            ]

        };
        BrowserDetect.init();
    </script>
        <script>
        function browserCheck() {
            var invalid = false;
            var browser = BrowserDetect.browser;
            var version = BrowserDetect.version;

            alert("Browser: " + browser + ", Version: " + version);



    if (browser == 'Firefox'){
            if (parseFloat(version) < parseFloat('3.0')){
                invalid = true;
            }
        } else if (browser == 'Explorer'){
            if (parseFloat(version) < parseFloat('8.0')){
                invalid = true;
            }
        } else {
            invalid = true;
        }

        if (invalid){
            //some action
        }
    }
    </script>
</head>
<body onload="browserCheck()">

</body>
</html>

Is there any reason why a specific site would show the wrong browser version?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:50:45+00:00Added an answer on May 24, 2026 at 6:50 am

    IE9 https://learn.microsoft.com/en-us/archive/blogs/ie/introducing-ie9s-user-agent-string and IE8 https://learn.microsoft.com/en-us/archive/blogs/ie/the-internet-explorer-8-user-agent-string-updated-edition have compatibility modes that fiddle with the User Agent (UA) string. So you can be using IE9 but viewing the website in Compatilbility mode which can change the UA to IE8, which is probably what you are seeing.

    If you don’t mind the added overhead of a complete library, jQuery has solid browser detection built in however, I believe it would still suffer the same problem if IE is spoofing the UA. Edit Actually, there does seem to be a workaround – see Detect IE8 Compatibility Mode, but again it’s probably a lot of overhead just for browser detection.

    Overall though (and as others have mentioned) UA sniffing is unreliable because it can be spoofed so easily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JavaScript code that works in IE containing the following: myElement.innerText =
I have some simple JavaScript that determines where a click happens within a browser
I have some javascript that I'm trying to retool using jQuery to learn the
I have some javascript that goes out and fetches a javascript class on another
Here is the situation. I have some javascript that looks like this: function onSubmit()
I have some Javascript code that will programmatically register an COM interop assembly by
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I have some jQuery/JavaScript code that I want to run only when there is
I have some third-party Javascript that has statements like this: FOO = function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.