在IE7兼容模式下区分IE7浏览器和浏览器 [英] Differentiate IE7 browser and browser in IE7 compatibility mode

查看:117
本文介绍了在IE7兼容模式下区分IE7浏览器和浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以区分客户端的浏览器是IE7还是IE9在IE7兼容模式下?我想弄清楚我是否可以在我的网站上进行JS检查,这会检查两种不同的东西并根据结果做不同的东西

Can I differentiate if client's browser is IE7 or e.g. IE9 in IE7 compatibility mode? I'm trying to figure out if I can do a JS check on my site which would recognize two different things and do different stuff depending on the result


  1. 浏览器是IE7

  2. 浏览器处于IE7兼容模式

我有第一个条件正常工作,因为它几乎到处都说如何做到这一点。不确定第二个和/或两者的组合。

I have the first condition working correctly as it's pretty much said everywhere how to do it. Not sure about the second one and/or combination of both.

推荐答案

至少对于IE8和IE9,你可以检查是否 navigator.userAgent 其中包含子字符串 Trident 。 IE8 + 始终在其用户代理中具有 Trident ,而IE7则没有。请参阅此答案其中的MSDN链接

For at least IE8 and IE9, you can check whether navigator.userAgent has the substring Trident in it. An IE8+ always has a Trident in its user-agent, where an IE7 doesn't. See this answer and the MSDN link in it.

IE10看起来比较棘手:在下面的评论中报告, Trident 在IE7仿真模式下不会始终如果在IE7可用的任何平台上IE10不可用,OS字符串(例如 Windows NT 6.2 )可能仍会显示IE10。

IE10 seems trickier: it is reported in the comments below that Trident is not always present with IE7 emulation mode. Probably the OS string (eg. Windows NT 6.2) will still reveal IE10, if IE10 will not be available on any platform where IE7 is available.

请注意,HTTP User-Agent 标题可能并不总是与导航器匹配。的userAgent 。至少IE9具有兼容模式(发送IE7​​ User-Agent 标头),但检测到类似 IE = Edge navigator.userAgent 转回IE9)。

Please also note that the HTTP User-Agent header might not always match navigator.userAgent. This is the case at least with IE9 that has compatiblity mode on (sends an IE7 User-Agent header) but detects something like IE=Edge in the response (navigator.userAgent turns back to IE9).

这篇关于在IE7兼容模式下区分IE7浏览器和浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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