2014-10-06 105 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

相關問題