【问题标题】:Why does navigator.appCodeName return Mozilla?为什么 navigator.appCodeName 返回 Mozilla?
【发布时间】:2010-05-06 11:23:34
【问题描述】:

以下 JavaScript 代码在所有浏览器上都返回“Mozilla”。为什么?

 <script type="text/javascript">
 document.write("Browser CodeName: " + navigator.appCodeName);
 </script>

【问题讨论】:

标签: javascript browser


【解决方案1】:

简答:因为人们认为用户代理检测(而不是feature (AKA object) detection)是个好主意,所以浏览器供应商开始撒谎以进行补偿。

长答案:History of the browser user-agent string

【讨论】:

  • 用户代理字符串一团糟,几乎没用,每个人都伪装成其他人,混乱比比皆是。
【解决方案2】:

许多年前,开发人员使用浏览器检测来拒绝其他浏览器,通常偏爱 Netscape Navigator(Mozilla 和 Firefox 的前身,也代号为 Mozilla)。他们在用户代理中测试了字符串'Mozilla'。 Internet Explorer 很生气,决定模仿 Netscape,这样他们就可以参与其中。

【讨论】:

    【解决方案3】:

    那个 navigator.appCodeName 基于 useragent 字符串,在 IE 的 useragent 字符串中,有 Mozilla 4.0 什么的,所以这两个都显示Mozilla

    【讨论】:

      【解决方案4】:
      猜你喜欢
      • 2021-11-13
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多