2014-10-06 76 views
0

我正在尝试做一些php浏览器测试。当我看着

$_SERVER['HTTP_USER_AGENT' 

我发现,它返回此:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko 

即使我是在IE 11

当我在Chrome,它返回此:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36 

哪个更合理。为什么IE中没有MSIE,我该如何定位它?

+2

。它的IE引擎。检查此http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx和此http://en.wikipedia.org/wiki/Trident_(layout_engine) – 2014-10-06 16:20:44

+0

http: //en.wikipedia.org/wiki/Comparison_of_web_browser_engines – PeeHaa 2014-10-06 16:21:42

回答

4

"Trident"是MSIE 11的布局引擎。正如你可以看到那里,当你在IE 11上它加载为Trident/7.0; rv:11.0)就像你在Chrome上它加载为AppleWebKit/537.36

如果您想了解更多关于浏览器的信息,可以随时使用PHP的get_browser()函数。

+0

在技术上,它的布局引擎来自MSIE8 – 2014-10-06 16:25:36

+0

@oPi,你是对的。但是,Wikipedia页面的[“Versions”](http://en.wikipedia.org/wiki/Trident_(layout_engine)#Versions)部分仍将其列为IE11的一部分。 – helllomatt 2014-10-06 16:27:13

+0

大声笑,这是我的坏。我读过“是MSIE 11的布局引擎”。对不起 – 2014-10-06 16:33:51

1

它的原因是来自8的MSIE通过TRIDENT标记其版本。我以前找过这个脚本。它还检测浏览器是否处于兼容模式。它可以帮助你,但它在JS:

编辑:一个简单的搜索,我发现原始代码在github

var ieUserAgent = { 
    init: function() { 
     // Get the user agent string 
     var ua = navigator.userAgent; 
     this.compatibilityMode = false; 
     // Detect whether or not the browser is IE 
     var ieRegex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 
     if (ieRegex.exec(ua) == null) 
      this.exception = "The user agent detected does not contain Internet Explorer."; 

     // Get the current "emulated" version of IE 
     this.renderVersion = parseFloat(RegExp.$1); 
     this.version = this.renderVersion; 

     // Check the browser version with the rest of the agent string to detect compatibility mode 
     if (ua.indexOf("Trident/7.0") > -1) { 
      if (ua.indexOf("MSIE 7.0") > -1) { 
       this.compatibilityMode = true; 
      } 
      this.version = 11;     // IE 11 
     } 
     else if (ua.indexOf("Trident/6.0") > -1) { 
      if (ua.indexOf("MSIE 7.0") > -1) { 
       this.compatibilityMode = true; 
      } 
      this.version = 10;     // IE 10 
     } 
     else if (ua.indexOf("Trident/5.0") > -1) {  
      if (ua.indexOf("MSIE 7.0") > -1) { 
       this.compatibilityMode = true; 
      } 
      this.version = 9;     // IE 9 
     } 
     else if (ua.indexOf("Trident/4.0") > -1) { 
      if (ua.indexOf("MSIE 7.0") > -1) { 
       this.compatibilityMode = true; 
      } 
      this.version = 8;     // IE 8 
     } 
     else if (ua.indexOf("MSIE 7.0") > -1) 
      this.version = 7;     // IE 7 
     else 
      this.version = 6;     // IE 6 
    } 
}; 

// Initialize the ieUserAgent object 
ieUserAgent.init(); 

$(document).ready(function() { 
    if(ieUserAgent.compatibilityMode) { 
     //do stuff 
    } 
    if(ieUserAgent.version == 6) { 
     //do stuff 
    } 
}); 
1

IE11丢弃用户代理字符串的“MSIE”部分。它不止于此 - navigator.appName将返回Netscapenavigator.product返回Gecko

可能的原因是IE11已经赶上了现代网络标准,微软不希望它在整个网络上触发旧的if(IE) { // shitty simpler website }处理程序。他们希望它看到Chrome/Firefox能够看到的全功能版本。带有Trident标签的

+0

没有不,他们一直在这样做之前,IE浏览器赶上_any_网络标准。看到这个笨蛋。 – 2014-10-07 12:15:35

+0

@LightnessRacesinOrbit多年来他们一直在添加东西,但删除密钥'MSIE'位是新的11. – ceejayoz 2014-10-07 13:28:35

+0

哦,对,好吧 – 2014-10-07 14:08:49

相关问题