为了账号安全,请及时绑定邮箱和手机立即绑定

如何检测IE11?

如何检测IE11?

如何检测IE11?当我要检测IE时,我使用以下代码:function getInternetExplorerVersion() {   var rv = -1;   if (navigator.appName == 'Microsoft Internet Explorer')   {     var ua = navigator.userAgent;     var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");     if (re.exec(ua) != null)       rv = parseFloat( RegExp.$1 );   }   return rv; } function checkVersion() {   var msg = "You're not using Internet Explorer.";   var ver = getInternetExplorerVersion();   if ( ver > -1 )   {     msg = "You are using IE " + ver;   }   alert( msg ); }但是IE 11正在返回“您没有使用InternetExplorer”。我怎么能发现它?
查看完整描述

3 回答

?
三国纷争

TA贡献1804条经验 获得超7个赞

IE11不再报告MSIE,根据此更改列表为了避免误检是故意的。

如果你真的想知道IE是用来检测Trident/的用户代理中的字符串。navigator.appName回报Netscape,类似于(未经测试的);

function getInternetExplorerVersion(){
  var rv = -1;
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  else if (navigator.appName == 'Netscape')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("Trident/.*rv:([0-9]{1,}[\\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;}console.log('IE version:', getInternetExplorerVersion());

请注意,IE11(AFAIK)仍然处于预览阶段,用户代理在发布前可能会更改。


查看完整回答
反对 回复 2019-07-12
?
DIEA

TA贡献1820条经验 获得超2个赞

使用!(window.ActiveXObject) && "ActiveXObject" in window以明确检测IE11。

若要检测任何IE(预边缘,“三叉戟”)版本,请使用"ActiveXObject" in window相反。


查看完整回答
反对 回复 2019-07-12
  • 3 回答
  • 0 关注
  • 775 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信