[英]If browser version is older than
我有一個簡單的問題 - 有沒有辦法做一些功能,檢測用戶是否使用較舊的瀏覽器版本,我可以自己設置?
如果這樣的聲明,有助於我做的事情:
if(chromeVersion <= 48 || firefoxVersion <= 52 || ieVersion <= 10 || ...)
{//do something}
我需要這個,因為我正在使用現代插件,舊版瀏覽器不支持它們,也無法預先修復它們。
祝你今天愉快!
獲取chrome版本:
function getChromeVersion () {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
}
對於多個瀏覽器
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);
嘗試如下
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") } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.