简体   繁体   中英

Why does navigator.appCodeName return Mozilla?

The following JavaScript code returns "Mozilla" on all browsers. Why?

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

Short answer: Because people thought that user agent detection (instead of feature (AKA object) detection ) was a good idea, so browser vendors started lying in order to compensate.

Long answer: History of the browser user-agent string

Many years ago, developers used browser detection to reject other browsers, usually favouring Netscape Navigator (precursor to Mozilla and Firefox, also codenamed Mozilla). They tested for the string 'Mozilla' in the user agent. Internet Explorer got angsty and decided to imitate Netscape so they could join in on the fun.

那 navigator.appCodeName 基于用户代理字符串和在 IE 的用户代理字符串中,有 Mozilla 4.0 之类的,所以这就是为什么它同时显示Mozilla原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM