本文介绍了为什么JavaScript的navigator.appName返回网景的Safari浏览器,Firefox和Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 navigator.appName 的Safari浏览器,Firefox和Chrome回归网景?

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级别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."

请参阅

See Mozilla documentation here.

BTW;这就是为什么这不能用于浏览器检测。 浏览器检测是一种不好的做法,你应该总是尽可能避免使用。做 来代替。但是,如果有人坚持这一点;他们应该使用的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 属性,以反映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...

更新2 微软边缘也返回网景 navigator.appName

UPDATE 2: Microsoft Edge also returns "Netscape" for navigator.appName.

这篇关于为什么JavaScript的navigator.appName返回网景的Safari浏览器,Firefox和Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 02:48