简体   繁体   中英

If browser version is older than

I have a simple question - is there a way to do some function, that detects if a user is using older browser version, that I can set myself?

Something that help me to do if statement like this:

if(chromeVersion <= 48 || firefoxVersion <= 52 || ieVersion <= 10 || ...)
{//do something}

I need this because of modern plugins that I'm using and they're not supported by older browsers and can't pre-fix them.

Have a nice day!

Get chrome version :

function getChromeVersion () {     
    var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);

    return raw ? parseInt(raw[2], 10) : false;
}

For multiple browser

 navigator.sayswho= (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(' '); })(); console.log(navigator.sayswho); 

Try as follows

 var x = navigator.userAgent.match(/(Opera|Chrome|Safari|Firefox|Msie|trident(?=\\/))\\/?\\s*(\\d+)/); console.log(x) if (x[1] == "Chrome") { alert("Chrome") if (x[2] == "63") { alert("Chrome version is 63") } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM