最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can I look up the user agent from JavaScript? - Stack Overflow

programmeradmin3浏览0评论

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 - but what about a similar thing for the user agent?

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.ybinator./item?id=1896015 - but what about a similar thing for the user agent?

Share Improve this question edited May 23, 2017 at 12:34 CommunityBot 11 silver badge asked Jan 25, 2012 at 20:28 cwdcwd 54.9k55 gold badges171 silver badges199 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

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:

  • IE: Conditional ments (HTML (also includes IE version) or in JScript)
  • Firefox / Webkit / Opera: Setting a CSS property with a vendor-prefix, and checking for the existence of the just-set property.

navigator.userAgent contains the user agent string of the browser.

发布评论

评论列表(0)

  1. 暂无评论