Internet Explorer 11 检测 [英] Internet Explorer 11 detection

查看:34
本文介绍了Internet Explorer 11 检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 IE 11 的用户代理字符串与所有其他 IE 不同

I know IE 11 has different user agent string than all other IE

 Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko

我试图用为此问题指定的答案检测 IE 11'

I have tried to detect IE 11 with answer specified for this question'

Jquery 无法检测到 IE 11

那就是!!navigator.userAgent.match(/Trident/7./)

但是我遇到了错误未找到对象,需要重新评估.

然后我在 IE11 中打开了开发者控制台并尝试访问一些预定义的 javascript 对象,我仍然遇到同样的错误.

Then I openede developer console in IE11 and tried to access some predefined javascript objects, I am still getting same error.

我试过了

navigator.userAgent

window.navigator

console.log('test');

有人知道吗?

推荐答案

Edit 18 Nov 2016

此代码也有效(对于那些更喜欢其他解决方案而不使用 ActiveX 的人)

var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
  // true on IE11
  // false on Edge and other IEs/browsers.

原答案

为了检查Ie11,你可以使用这个:(已测试)

In order to check Ie11 , you can use this : ( tested)

(或运行 this)

!(window.ActiveXObject) &&窗口中的ActiveXObject"

我有 IE 的所有 VMS:

I have all VMS of IE :

注意:这不适用于 IE11:

Notice : this wont work for IE11 :

正如你在这里看到的,它返回真:

as you can see here , it returns true :

那我们能做什么:

显然,他们添加了机器位空间:

Apparently , they added the machine bit space :

ie11:

"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko"

ie12:

"Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko"

所以我们可以这样做:

/x64|x32/ig.test(window.navigator.userAgent)

这只会对 ie11 返回 true.

this will return true only for ie11.

这篇关于Internet Explorer 11 检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆