本文主要是介绍浏览器版本重新判断(IE11革新后),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
IE11对ie的好多地方进行了修改,兼容了标准,userAgent改变,但其实感觉它已经不是ie了。
改变参照学习链接:链接1 链接2
修改后的js代码:
/*** Usually used browser compatibility.<br>* Get browser name agent version.<br>* return browser name and version.<br>* return eg:ie9.0、ie11.0、firefox34.0、chrome37.0* */
function getBrowserNV(){var agent = navigator.userAgent.toLowerCase();var regStr_ie = /msie [\d.]+/gi ;var regStr_ff = /firefox\/[\d.]+/givar regStr_chrome = /chrome\/[\d.]+/gi ;var regStr_saf = /safari\/[\d.]+/gi ;var browserNV = "";//IEif(agent.indexOf("msie") > 0){browserNV = agent.match(regStr_ie) ;}//firefoxif(agent.indexOf("firefox") > 0){browserNV = agent.match(regStr_ff) ;}//Chromeif(agent.indexOf("chrome") > 0){browserNV = agent.match(regStr_chrome) ;}//Safariif(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0){browserNV = agent.match(regStr_saf) ;}browserNV = browserNV.toString();//otherif(""==browserNV){browserNV = "Is not a standard browser";}//Here does not display "/"if(browserNV.indexOf('firefox')!= -1 || browserNV.indexOf('chrome')!= -1){browserNV = browserNV.replace("/","");}//Here does not display spaceif(browserNV.indexOf('msie')!= -1){//msie replace IE & trim spacebrowserNV = browserNV.replace("msie","ie").replace(/\s/g,"");}if(browserNV == "Is not a standard browser"){if(isIE()){browserNV = "ie11.0";}}//return eg:ie9.0 firefox34.0 chrome37.0return browserNV;
}
//IE11
function isIE() { //IEif (!!window.ActiveXObject || "ActiveXObject" in window)return true;elsereturn false;
}
使用代码:
//标签的css样兼容解决var bnv = getBrowserNV().toString();if(bnv.indexOf("ie") != -1 || bnv.indexOf("chrome") != -1){$("#attentiondiv").find("dd").addClass("attentdd");$("#attentiondiv").find(".no_dt").addClass("attentnodt");}
这篇关于浏览器版本重新判断(IE11革新后)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!