本篇文章乃本菜鸟搜的,手机下来以备以后使用!
功能:判断浏览器版本以及IE的版本号
废话不多说,无码无真相:
function userAgent(){
var ua = navigator.userAgent;
ua = ua.toLowerCase();
var match = /(webkit)[ \/]([\w.]+)/.exec(ua) ||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||/(msie) ([\w.]+)/.exec(ua) ||!/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) ||[];
//match[2]判断版本号
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) == 6) //ie6
alert("ie6");
else if (parseInt(match[2]) == 7) //ie7
alert("ie7");
else if (parseInt(match[2]) == 8) //ie8
alert("ie8");
break;
case "webkit": //safari or chrome
alert("safari or chrome");
break;
case "opera": //opera
alert("opera");
break;
case "mozilla": //Firefox
alert("Firefox");
break;
default:
break;
}
}
点滴积累,汇聚强大自己!
欢迎交友交流,前端交流可加QQ:1740437
本屌丝也热爱古风,包括音乐,cosplay,有兴趣的可加QQ群:300017860