How can I find out which browser a user is using?

10,951

Solution 1

function BrowserDetection() {

        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {

            var ffversion = new Number(RegExp.$1) ;     
        }

        else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {

            var ieversion = new Number(RegExp.$1);       
        }

        else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            var chromeversion = new Number(RegExp.$1);
            // capture x.x portion and store as a number

        }
        else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {

            var oprversion = new Number(RegExp.$1) 
        }
        else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            var safariversion = new Number(RegExp.$1);


        }

        }

Then after finding the version, u will compare and display popup according to your need.

Solution 2

Check out this browser detection script:

http://www.quirksmode.org/js/detect.html

Solution 3

Don't detect browsers, detect browser features. There's a good discussion on Stack Overflow already:

Browser detection versus feature detection

Share:
10,951
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    I would like to show a pop-up telling the user if their browser is outdated. How can I find out what browser they are using in javascript?

  • Bryan Grace
    Bryan Grace over 7 years
    This isn't an answser to the question. Who care's what people think.