问题描述
为什么 navigator.appName
为 Safari、Firefox 和 Chrome 返回Netscape"?
Why does navigator.appName
return "Netscape" for Safari, Firefox and Chrome?
它们与旧的浏览器 Netscape 有什么关系?会不会是因为DOM0?
What do they have to do with the old browser Netscape? Could it be because of DOM0?
推荐答案
是的,这是为了兼容性问题,不能依赖.
MDN 说:这最初是 DOM Level 0 的一部分,但后来被包含在 HTML5 规范中."
Yes and that's for compatibility issues and not to be relied on.
MDN says: "This was originally part of DOM Level 0, but has been since included in the HTML5 spec."
在此处查看 Mozilla 文档.
See Mozilla documentation here.
顺便说一句;这就是为什么这不能用于浏览器检测的原因.浏览器检测是一种不好的做法,您应该始终尽可能避免它.改为执行特征检测.但如果有人坚持这一点;他们应该改用 userAgent
属性.
BTW; that's why this cannot be used for browser detection. Browser detection is a BAD practice and you should always avoid it where possible. Do feature detection instead. But if anybody insists on this; they should use the userAgent
property instead.
更新 1:根据 兼容性变化;IE11 现在还为 navigator.appName
属性返回 "Netscape"
,以反映 HTML5 标准并匹配其他浏览器的行为.另请参阅 userAgent
字符串中的更改 此处...有关特征检测的更多信息此处...
UPDATE 1: According to Compatibility Changes; IE11 now also returns "Netscape"
for navigator.appName
property, to reflect the HTML5 standard and to match behavior of other browsers. Also see changes in userAgent
string here... More on feature detection here...
UPDATE 2:Microsoft Edge 还为 navigator.appName
返回 "Netscape"
.
UPDATE 2: Microsoft Edge also returns "Netscape"
for navigator.appName
.
这篇关于为什么 JavaScript navigator.appName 为 Safari、Firefox 和 Chrome 返回 Netscape?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!