Is window.navigator.userAgent really going to be deprecated?

I just read on MDN about window.navigator.userAgent:

Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

I am not finding any other significant reference on the web confirming this statement. User agent information are widely used by many companies for various reasons (analytics, bug fixes in specific browser ...). While I understand that one should use feature detection over ua sniffing it just seems incredible that this information would go away.

Is it really going away or is it just a Mozilla thing?

If so, is there a replacement for it?


The deprecation notice seems to be gone now. It was removed yesterday, over a year after this question was first asked, with the following comment:

rm deprecation marker. This is not removed from the living spec and no deprecation either. Most use cases are discouraged for quality reasons, but that's something else.

The WHATWG Living standard hasn't deprecated this property, so that confirms that the property isn't going away. Sure, it's a crapshoot and easily spoofed, but "not recommended for use" is not the same as "deprecated". As you note, too many authors and organizations depend on this property for it to be simply specced out of existence and removed from implementations.

Perhaps confusion over the meaning of the word "deprecated" is what resulted in the deprecation notice in the first place. The article itself is still incorrectly tagged "Deprecated", by the way.

Note that Mozilla is not responsible for contributions to the MDN docs. The community is. And as with any other community-curated, unofficial knowledge base (including this very site), don't treat its information as gospel, always cross-reference, etc (as you have done here).


Use feature detection. If you need to use feature X, test to see if X is available.

链接地址: http://www.djcxy.com/p/89192.html

上一篇: 合并两个重叠的字符串

下一篇: window.navigator.userAgent真的会被弃用吗?