30

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

 <script type="text/javascript">
 document.write("Browser CodeName: " + navigator.appCodeName);
 </script>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Venkat
  • 20,802
  • 26
  • 75
  • 84
  • Does this answer your question? [Why do all browsers' user agents start with "Mozilla/"?](https://stackoverflow.com/questions/1114254/why-do-all-browsers-user-agents-start-with-mozilla) – Dharman Dec 02 '21 at 15:26

4 Answers4

42

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

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • the user agent string was a complete mess, and near useless, and everyone pretended to be everyone else, and confusion abounded. – mujaffars May 11 '16 at 09:03
11

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.

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
1

That navigator.appCodeName based on useragent string and In IE's useragent string, there is Mozilla 4.0 or something, so thats why its display Mozilla for both.

YOU
  • 120,166
  • 34
  • 186
  • 219