0

Possible Duplicate:
How would I identify if a website originates from a mobile browser?

I am working on a website in Asp.Net 4.0 and this site has also all mobiles version sites. Now my requirement is that i want to know that when user opens my site at that time in my javascript code captured it that this site runs on PC or Tablet or Mobile and its related operation system and browser also.

Community
  • 1
  • 1
Gaurav Agrawal
  • 4,355
  • 10
  • 42
  • 61
  • Put a button on the site to go from one version to another. Just because a user is using a particular device doesn't mean they want to only access sites designed for that device. And what about devices you fail to correctly identify? – RobG Jan 11 '12 at 07:19

2 Answers2

2

If you do not trust the useragent header value because of spoofing or adjustable useragents in tablet/mobile browsers you may use some heuristical solution like here.

fyr
  • 20,227
  • 7
  • 37
  • 53
0

Use navigator.userAgent to get the user agent string - You can parse this to get the platform, browser etc.

techfoobar
  • 65,616
  • 14
  • 114
  • 135
  • The user agent string is pretty useless for most things. It might provide a hint about platform and OS, but you can't rely on it. e.g. what does this string tell you about the device: `Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.8 (KHTML, like Gecko) Chrome/4.0.295.0 Safari/532.8` – RobG Jan 11 '12 at 07:14
  • Yes, UA strings can be pretty useless depending on the browser/platform being used. The only plus with the approach is that for browsers with good UA strings (indicating platform etc..) this is easy to do. But again this will work only for a percentage of the users, not all. – techfoobar Jan 11 '12 at 07:22