我可以从 JavaScript 查找用户代理吗?
我们知道可以使用 JSON 和回调查找访问者的 IP,如下所示 我可以使用客户端 Javascript 执行 DNS 查找(主机名到 IP 地址)吗? 以及 http://news.ycombinator.com/item?id=1896015 - 但是怎么样用户代理有类似的事情吗?
We know it's possible to look up the IP of a visitor using JSON and a callback, as seen here Can I perform a DNS lookup (hostname to IP address) using client-side Javascript? and also at http://news.ycombinator.com/item?id=1896015 - but what about a similar thing for the user agent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该字符串可直接在
navigator.userAgent
。然而,这个字符串不是很可靠,因为用户可以很容易地修改它。仅将其用于非关键目的。如果您想检测用户代理,以便您“知道”支持什么,您最好切换到功能检测。
检测浏览器的替代方法示例:
This string is directly available in
navigator.userAgent
. However, this string is not very reliable, because the user can easily modify it. Only use it for non-critical purposes.If you want to detect the user agent, so that you "know" what's supported, you'd better switch to capability-detection.
Examples of alternative methods to detect the browser:
navigator.userAgent
包含浏览器的用户代理字符串。navigator.userAgent
contains the user agent string of the browser.