公司要求做内部统计,要求监控客服玩游戏使用的浏览器的型号,是火狐的、谷歌的、还是IE的等等。
[code lang="javascript"]
/****
* 目前识别范围
* Microsoft Internet Explorer IE浏览器
* --> TheWorld 世界之窗
* --> TT浏览器
* --> 360浏览器
* --> 猎豹浏览器
* Mathon 傲游浏览器
* Opera Opera浏览器
* Firefox 火狐浏览器
* Chrome Chrome浏览器
* */
var browseInfo = {
//isMobile 是否移动终端
//browse 浏览器标识
//name 浏览器名称
//version 浏览器 版本
//extend 浏览器扩展标识
};
browseInfo.isMobile=!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/);
alert(navigator.userAgent);
if(navigator.appName.indexOf("Microsoft Internet Explorer")!=-1 && document.all)
{
browseInfo.browse = "IE";
browseInfo.name = "IE浏览器";
browseInfo.extend = "";
var ver = navigator.userAgent.toLowerCase();
ver = ver.substring(ver.indexOf("msie"),ver.length);
ver = ver.substring(0,ver.indexOf(";"))
browseInfo.version = ver.replace("msie ","");
//世界之窗 浏览器
if(navigator.appVersion.toLowerCase().indexOf("theworld") > -1)
{
browseInfo.extend = "TheWord";
browseInfo.name = "世界之窗浏览器";
}else if(navigator.appVersion.toLowerCase().indexOf("tencenttraveler") > -1)
{
browseInfo.extend = "TT "+navigator.appVersion.substring(0,3);
browseInfo.name = "TT浏览器";
}else if(navigator.appVersion.toLowerCase().indexOf("lbbrowser") > -1)
{
browseInfo.extend = "LB";
browseInfo.name = "猎豹浏览器";
}else if(window.external+"" == "undefined" || window.external == undefined)
{
//网站不能识别你的浏览器 不支持window.external 很可能为360浏览器
browseInfo.extend = "360SE";
browseInfo.name = "360浏览器";
}
}else if(navigator.appName.indexOf("Netscape")!=-1)
{
browseInfo.browse = "Netscape";
browseInfo.version = navigator.appVersion.substring(0,3);
//移动 客户端
if(browseInfo.isMobile)
{
var vers = navigator.appVersion.substring(navigator.appVersion.indexOf("Mobile")+7,navigator.appVersion.length);
var arrs = vers.split(" ");
vers = arrs[arrs.length-1];
browseInfo.browse = vers.split("/")[0];
browseInfo.version = vers.split("/")[1];
browseInfo.name = browseInfo.browse+"手机浏览器";
}
////非移动 客户端
else
{
if(window.external && window.external.max_version && navigator.userAgent.toLowerCase().indexOf("maxthon")>=0 )
{
browseInfo.browse = "Mathon";
browseInfo.version = window.external.max_version;
browseInfo.name = "遨游浏览器";
}else if(navigator.userAgent.indexOf("Firefox")!=-1)
{
browseInfo.browse = "Firefox";
browseInfo.name = "火狐浏览器";
browseInfo.version = navigator.userAgent.substr((navigator.userAgent+"").lastIndexOf('/')+1);
}else if(navigator.userAgent.indexOf("Chrome")!=-1)
{
browseInfo.browse = "Chrome";
browseInfo.name = "Chrome浏览器";
var subVersion = navigator.appVersion.substring(navigator.appVersion.indexOf("Chrome")+7);
browseInfo.version = subVersion.substring(0,subVersion.indexOf(' '));
}
}
}else if(navigator.userAgent.indexOf("Opera")!=-1)
{
browseInfo.browse = "Opera";
browseInfo.name = "Opera浏览器";
browseInfo.version = navigator.appVersion.substring(0,3);
}else
{
browseInfo.browse = "Unknown";
browseInfo.name = "未知"+(browseInfo.isMobile?"手机":"")+"浏览器";
browseInfo.version = "1.0";
}
// if(browseInfo.browse != "IE" || browseInfo.extend != "")
// {
// alert("目前系统对IE浏览器兼容性比较好,\n你的浏览器为"+browseInfo.name+",\n如果办理业务建议使用系统自带的IE浏览器。");
// }
alert(browseInfo.name+"[version="+browseInfo.version+"]");
[/code]