您的位置:首页 > Web前端 > JavaScript

js获取浏览器类型

2014-05-15 13:56 316 查看
function getBrowserType()
{
var ug = navigator.userAgent.toLowerCase();
var browserType = "Other";
var ver = "";

if ( ug.indexOf( "360se" ) >= 0 || ug.indexOf( "360ee" ) >= 0 )
return "360";
else if ( ug.indexOf( "maxthon" ) >= 0 )
return "Maxthon";

var isIE = !!window.ActiveXObject;
if ( isIE )
{
browserType = "IE";
var isIE6 = !window.XMLHttpRequest;
var isIE8 = !!document.documentMode;
var isIE7 = !isIE6 && !isIE8;

var isIE9 = ug.match(/msie\s*9\.\d+/) != null;
if ( isIE9 ){
ver = "9.0"
}
else if (isIE6){
ver = "6.0"
}
else if (isIE8){
ver = "8.0"
}
else if (isIE7){
ver = "7.0"
}

return browserType + " " + ver;
}

//chrome
var chrome = ug.match(/chrome\/\d+\.\d+/);
if( chrome != null ) {
browserType = "Chrome";
ver = chrome.join(" ").match(/\d+/g).join(".");
return browserType + " " + ver;
}

//firefox
var firefox = ug.match(/firefox\/\d+\.\d+/);
if( firefox != null ) {
browserType = "Firefox";
ver = firefox.join(" ").match(/\d+/g).join(".");
return browserType + " " + ver;
}

return browserType + " " + ver;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: