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

查看:203
本文介绍了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');

任何人都有任何想法吗?

Anyone have any idea about it ?

解决方案

编辑2016年11月18日

此代码也适用(适合喜欢的人另一个解决方案,不使用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)

(或运行这个

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

我拥有IE的所有VMS:

I have all VMS of IE :

< img src =https://i.stack.imgur.com/JvkyG.jpgalt =在此输入图像说明>

注意:这不适用于IE12:

Notice : this wont work for IE12 :

如你所见,它返回true:

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)

这将仅对ie12返回true。

this will return true only for ie12.

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

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