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

查看:34
本文介绍了区分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 仿真模式中.可能操作系统字符串(例如 Windows NT 6.2)仍会显示 IE10,如果 IE10 在 IE7 可用的任何平台上都不可用.

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 标头可能并不总是匹配 navigator.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天全站免登陆