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

11.1k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER
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.

0
On

Check out this browser detection script:

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

1
On

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

Browser detection versus feature detection