How to detect old versions of browsers? [duplicate]

0

In my current development I want to show a message if my libraries are not compatible with the browser versions. I am using axios v0.18.0, jquery v3.3.1, vuejs v2.5.17, lodash v4.17.11 and materialize v1.0.0.

IE 11 down I do not accept my code for the functions arrow (= >), when making asynchronous requests or based on promises.

Safari Not supported by vue from version 10.10 down.

Etc.

I would like in these cases (when the browser does not have support in the libraries that I use). Take a message where I recommend my users to install an updated version of their browser or use chrome or firefox.

For this I have a code that reads the browser version.

 var getBrowserInfo = function() {
            var ua= navigator.userAgent, tem, 
            M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
            
            if(/trident/i.test(M[1])){
                tem=  /\brv[ :]+(\d+)/g.exec(ua) || [];
                return 'IE '+(tem[1] || ''); 
            }
            if(M[1]=== 'Chrome'){
                tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
                if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
            }
            M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
            if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);

            return M.join(' ');
        };

        let a = getBrowserInfo();
        
        console.log(a)

But what I do not know is what message it returns when it runs, for example, in IE6 or when it runs in Safari 9.

So what I need to know is how the code will return the name of the browser to put it in my list of exceptions.

    
asked by Alberto Ortega 29.10.2018 в 21:33
source

2 answers

0

This javascript code returns the browser and the version:

var browser = '';
var browserVersion = 0;

if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    browser = 'Opera';
} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
    browser = 'MSIE';
} else if (/Navigator[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    browser = 'Netscape';
} else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    browser = 'Chrome';
} else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    browser = 'Safari';
    /Version[\/\s](\d+\.\d+)/.test(navigator.userAgent);
    browserVersion = new Number(RegExp.$1);
} else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    browser = 'Firefox';
}
if(browserVersion === 0){
    browserVersion = parseFloat(new Number(RegExp.$1));
}
alert(browser + "*" + browserVersion);

Translated from Chamika Sandamal stackOverflow

Greetings

    
answered by 29.10.2018 в 21:46
0

I share this link , specifically the section "Check for Internet Explorer version". There you can find methods to apply styles or execute functions only in the versions you want to point to.

    
answered by 29.10.2018 в 21:50