为什么 JavaScript navigator.appName 为 Safari、Firefox 和 Chrome 返回 Netscape?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14573881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does JavaScript navigator.appName return Netscape for Safari, Firefox and Chrome?
提问by C graphics
Why does navigator.appNamereturn "Netscape" for Safari, Firefox and Chrome?
为什么navigator.appNameSafari、Firefox 和 Chrome会返回“Netscape”?
What do they have to do with the old browser Netscape? Could it be because of DOM0?
它们与旧的浏览器 Netscape 有什么关系?可能是因为 DOM0 吗?
采纳答案by Onur Y?ld?r?m
Yes and that's for compatibility issues and not to be relied on.
MDNsays: "This was originally part of DOM Level 0, but has been since included in the HTML5 spec."
是的,这是为了兼容性问题,不能依赖。
MDN说:“这最初是 DOM Level 0 的一部分,但后来被包含在 HTML5 规范中。”
See Mozilladocumentation here.
BTW; that's why this cannot be used for browser detection. Browser detection is a BAD practiceand you should always avoid it where possible. Do feature detectioninstead. But if anybody insists on this; they should use the userAgentproperty instead.
顺便提一句; 这就是为什么这不能用于浏览器检测的原因。浏览器检测是一种不好的做法,您应该始终尽可能避免它。做特征检测来代替。但如果有人坚持这一点;他们应该改用该userAgent财产。
UPDATE 1: According to Compatibility Changes; IE11now also returns "Netscape"for navigator.appNameproperty, to reflect the HTML5 standard and to match behavior of other browsers. Also see changes in userAgentstring here... More on feature detection here...
更新 1:根据兼容性更改;IE11现在也返回"Netscape"了navigator.appName属性,以反映HTML5标准,并符合其他浏览器的行为。还可以在此处查看userAgent字符串中的更改...此处有关特征检测的更多信息...
UPDATE 2: Microsoft Edgealso returns "Netscape"for navigator.appName.
更新 2:Microsoft Edge也返回"Netscape"了navigator.appName.
回答by xlharambe
Based on Johnny Stenback's post:
基于 Johnny Stenback 的帖子:
This was debated on the mozilla newsgroups ages ago and it was decided that navigator.appName should return 'Netscape' even in mozilla since if that were to be changed every page out on the web that uses some browser sniffing code (and that's a HUGE part of the current web) would need to recognize mozilla, and that just won't happen and there's no reason to do that either since mozilla == netscape == mozilla as far as content developers are conserned.
这在很久以前就在 mozilla 新闻组上进行了辩论,并且决定即使在 mozilla 中 navigator.appName 也应该返回“Netscape”,因为如果要更改网络上使用某些浏览器嗅探代码的每个页面(这是一个巨大的部分)当前网络的)需要识别 mozilla,而这不会发生,也没有理由这样做,因为 mozilla == netscape == mozilla 就内容开发人员而言。
Source here.
来源在这里。
回答by magikMaker
Starting in IE11, Explorer will now also return "Netscape" when calling navigator.appName;
从 IE11 开始,资源管理器现在在调用 navigator.appName 时也会返回“Netscape”;
UpdateAlthough this answer is rather outdated by now, here is the link for the statement above: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/dev-guides/bg182625(v=vs.85)?redirectedfrom=MSDN#legacy-api-additions-changes-and-removals
更新虽然这个答案现在已经过时了,但这里是上述声明的链接:https: //docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/dev-guides /bg182625(v=vs.85)?redirectedfrom=MSDN#legacy-api-additions-changes-and-removals

