代码:
复制代码 代码示例:
// 获取浏览器类型
function getUserAgentType() {
var userAgentType = "";
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
if (userAgent.indexOf("Opera") > -1){ //判断是否Opera浏览器
userAgentType = "Opera";
}
if (userAgent.indexOf("Firefox") > -1){//判断是否Firefox浏览器
userAgentType = "FF";
}
if (userAgent.indexOf("Safari") > -1){//判断是否Safari浏览器
userAgentType = "Safari";
}
if (userAgent.indexOf("MSIE") > -1){//判断是否IE浏览器
userAgentType = "IE";
}
return userAgentType;
}
//获取IE版本
function getIEVersion(){
var appName = navigator.appName;
var userAgent = navigator.userAgent;
var version;
if(appName == 'Microsoft Internet Explorer'){
version = /MSIEs(S)/.exec(userAgent)[1];
versionfloat = parseFloat(version);
return versionfloat;
}
return null;
}