[英]IF IE conditional comment in JavaScript?
I need to display a text eg "You are using Internet Explorer browser" within the div for all users using IE browsers (6-11). 我需要在div中为所有使用IE浏览器的用户显示文本,例如“您正在使用Internet Explorer浏览器”(6-11)。 MS has dropped conditional comments as of IE10 so I'm unable to do so via css.
MS已经删除了IE10的条件评论,所以我无法通过css这样做。 Any advice?
有什么建议?
Use navigator.userAgent
: 使用
navigator.userAgent
:
function isIE () {
var myNav = navigator.userAgent.toLowerCase();
if( myNav.indexOf('msie') > -1 || myNav.indexOf('.net') > -1) {
// do stuff;
}
}
myNav.indexOf('.net')
is needed to detect IE 11 , all other versions have msie
in the UA string. myNav.indexOf('.net')
来检测IE 11 ,所有其他版本在UA字符串中都有msie
。
use ie conditional compilation to target 10/11, which is essentially conditional comments in javascript. 使用即条件编译来定位10/11,这基本上是javascript中的条件注释。 you can see a demo here: http://dev.bowdenweb.com/ua/browsers/ie/ie10-detection-via-cc.html
你可以在这里看到一个演示: http : //dev.bowdenweb.com/ua/browsers/ie/ie10-detection-via-cc.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.