方法1
资料地址:http://blog.csdn.net/cymit/article/details/5756829
方法2:
资料地址:http://blog.csdn.net/aerchi/article/details/51697592
实际使用案例如下:
//author: aerchi
//site:www.aerchi.com //blog: http://blog.csdn.net/aerchi/article/details/51697592 //email: aerchi@gmail.com //date: 2016-06-17 //update: 2016-08-11 00:56:00 //call like: getBrowser(1) //return like "chrome/50.0.2661.102" //call like: getBrowser() //return like "chrome" function getBrowser(getVersion) { //注意关键字大小写 var ua_str = navigator.userAgent.toLowerCase(), ie_Tridents, trident, match_str, ie_aer_rv, browser_chi_Type; console.log("article url: http://blog.csdn.net/aerchi/article/details/51697592");//判断IE 浏览器,
//blog: http://blog.csdn.net/aerchi/article/details/51697592 if("ActiveXObject" in self){ // ie_aer_rv: 指示IE 的版本. // It can be affected by the current document mode of IE. ie_aer_rv= (match_str = ua_str.match(/msie ([\d.]+)/)) ?match_str[1] : (match_str = ua_str.match(/rv:([\d.]+)/)) ?match_str[1] : 0;// ie: Indicate the really version of current IE browser.
ie_Tridents = {"trident/7.0": 11, "trident/6.0": 10, "trident/5.0": 9, "trident/4.0": 8}; //匹配 ie8, ie11, edge trident = (match_str = ua_str.match(/(trident\/[\d.]+|edge\/[\d.]+)/)) ?match_str[1] : undefined; browser_chi_Type = (ie_Tridents[trident] || ie_aer_rv) > 0 ? "ie" : undefined; }else{ //判断 windows edge 浏览器 // match_str[1]: 返回浏览器及版本号,如: "edge/13.10586" // match_str[1]: 返回版本号,如: "edge" //若要返回 "edge" 请把下行的 "ie" 换成 "edge"。 注意引号及冒号是英文状态下输入的 browser_chi_Type = (match_str = ua_str.match(/edge\/([\d.]+)/)) ? "ie" : //判断firefox 浏览器 (match_str = ua_str.match(/firefox\/([\d.]+)/)) ? "firefox" : //判断chrome 浏览器 (match_str = ua_str.match(/chrome\/([\d.]+)/)) ? "chrome" : //判断opera 浏览器 (match_str = ua_str.match(/opera.([\d.]+)/)) ? "opera" : //判断safari 浏览器 (match_str = ua_str.match(/version\/([\d.]+).*safari/)) ? "safari" : undefined; }console.log("author: aerchi, blog: http://blog.csdn.net/aerchi");
//返回浏览器类型和版本号 var verNum, verStr; verNum = trident && ie_Tridents[trident] ? ie_Tridents[trident] : match_str[1]; verStr = (getVersion != undefined) ? browser_chi_Type+"/"+verNum : browser_chi_Type; return verStr; } var browser=getBrowser(); if(browser=="ie"){ $("#myBarChart").css({"height":"calc(100%- 14px)"}); $("#myLineChart").css({"height":"calc(100%- 14px)"}); }if(browser=="firefox"){
$("#myBarChart").css({"height":"360px"}); $("#myLineChart").css({"height":"360px"}); }