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 8409973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:03:33+00:00 2026-06-10T00:03:33+00:00

I am building a page that will allow a simple user to check their

  • 0

I am building a page that will allow a simple user to check their browser version and then depending on what browsers and operating system will show a certain div. Then based on version add a certain class to a tag.

I found this code to detect the browser, version, and operating system. Code Follows:

// Detect Browser and OS
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) {
    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",
        versionSearch: "Version"
    },
    {
        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/iPad"
    },
    {
        string: navigator.platform,
        subString: "Linux",
        identity: "Linux"
    }
]

  };
BrowserDetect.init();

I do not know where to start with the javascript to show certain divs.

My idea is that based on what the above code shows it will either show a red or green button based on the version number and a DIV. For example if the browser is Internet Explorer and the Version is 8 then it will show a red button and a div with certain options.

Idea for code:

<div style="width:400px;" class="center">
<script type="text/javascript">
document.write('<p class="[insert either red or green based on version   number]-button">You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + '</p>');
</script>   
</div>   

<!-- Show either Outdated DIV or Up to Date Div based on version number I specify. -->
<div id="outdated">
<!-- Content -->
</div>
<div id="up-to-date">
<!-- Content -->
</div>

<!-- Show if Windows -->
<div id="windows">
<!-- Content -->
</div>

<!-- Show if MAC -->
<div id="mac">
<!-- Content -->
</div>

<!-- Show if Linux -->
<div id="linux">
<!-- Content -->
</div>

<!-- Show if Unknown or Other -->
<div id="other">
<!-- Content -->
</div>

Example

Let us say an user visit the page and is running Firefox 10 on Windows. The following code would show:

<div style="width:400px;" class="center">
<script type="text/javascript">
document.write('<p class="red-button">You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + '</p>');
</script>   
</div>   

<div id="outdated">
<p>You are using an outdated browser.</p>
</div>

<div id="windows">
<!-- Links to update browser. -->
</div>

I hope this is clear and I will answer any and all questions. I have not attempted any code so far as I do not know where to start beyond detecting the bowser, version, and OS.

I cannot use any server side scripting. I am using a hosted CMS and do not have server side access. I am using jQuery 1.8 on my page however I do not want to use $.browser since it is deprecated. (With that said if it is much easier or the only was to do this in just JS then I am willing to use it and will maintain an older version of jQuery for this page.) Also I assume that I will have to manually specify what versions are outdated and not. (I.E. If version is less than 14 the browser is outdated.) If there is a way to tell the script what is the most updated version released then great but not required.

An Important Note: I am a novice at JS and open to any and all code that will work for my purposes which are creating a simple and easy to use page for a user of my service/site to check their browser and browser version. While normally I would agree that user agent sniffing should be avoided in this case I do not see a way around it to do what I would like. Since I am a novice please provide examples.

  • 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-06-10T00:03:34+00:00Added an answer on June 10, 2026 at 12:03 am

    Fair enough. I can see that you’re forced to use JS, and honestly, this script is about as good as it’s going to get.

    With the above code in place, you’ll want to use what I provide to you after that script.

    BrowserDetect.init();
    

    Let’s assume we have a div in place.

    <div id="userInfo"></div>
    

    Now we’ll need to write out conditional statements for the version/platforms. This is going to be a long list, because unfortunately you need to reverse engineer this code to work as you’d want.

    var a = BrowserDetect.browser,
    b = BrowserDetect.version,
    c = BrowserDetect.OS;
    if(a == "Firefox" && b >= "14" && c == "Windows"){
        //firefox greater then or equal to 14, on windows
        $("#userInfo").text(a +' '+ b + ' - ' + c);
    }else if(a == "Explorer" && b == "9" && c == "Windows"){
        //ie9 on windows
        $("#userInfo").text(a +' - '+ b + ' - ' + c);   
    }else if(a == "Chrome" && b > "19" && c == "Mac"){
        //chrome greater than 19 on a mac
        $("#userInfo").text(a +' - '+ b + ' - ' + c); 
    }
    //more conditionals here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a page that will allow a user to upload an MP3 file.
I'm building a Page Tab application that will allow Facebook users to make purchases
I'm building a login form composite component. The page that uses it will pass
I am building a web application that will essentially allow authenticated users access to
I'm building a web app that will (ideally) allow users to follow discussion threads
I am building a page with a restaurant menu that will consist of a
I am building a page that will animate objects (image/shape/div) and float them around
I'm building a one page form that will create a model and it's relations.
I'm building a review site that will allow users to submit reviews which will
I am building a page that will have multiple instances of a tag such

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.