我怎么能只针对Internet Explorer的11用JavaScript? [英] How can I target only Internet Explorer 11 with JavaScript?

查看:124
本文介绍了我怎么能只针对Internet Explorer的11用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最不容易出错的方式只针对使用JavaScript IE11?

What's the least error-prone way to target just IE11 with JavaScript?

请注意:这应该真的只为分析或告知他们正在使用的浏览器用户来完成。对于一切,有特征检测。

Note: This should really only be done for analytics or informing the user what browser they're using. For everything else, there's feature detection.

推荐答案

有关IE 11的用户代理字符串是目前这一个:

The User-agent string for IE 11 is currently this one :

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

这意味着你可以简单地测试,为11.XX版本,

Which means your can simply test, for versions 11.xx,

var isIE11 = navigator.userAgent.test(/Trident.*rv[ :]*11\./)

由于 IE10用户代理是

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)

这可能也可以放心下注的事实,现在三叉戟/ X 应该是真正的versionning。

it's probably also safe to bet on the fact that now Trident/X is supposed to be the real versionning.

这篇关于我怎么能只针对Internet Explorer的11用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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