#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0

    Is window.navigator.userAgent reliable


    Is this a reliable means of device detection, ie iPad, iPhone, Android, etc.. ?

    Or is there a sensible alternative ?

    Is there a definitive list of device names ?

    Many thanks..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    40
    Rep Power
    9
    You can detect mobile device with jquery and javascript, but you need to google for this code
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0
    Based on w3schools, it should be supported by all browsers, so it should be a pretty reliable method for detecting the user agent.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0
    Not very enlightening, what happens to the value of .userAgent if the user changes the browser config ?
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,129
    Rep Power
    4304
    It changes. User agent strings are inherently somewhat unreliable.

    For what purposes are you trying to detect which device is being used? It's generally better to check viewport (not screen) dimensions and do feature detection instead of relying on user-agent sniffing.

    There are dozens and dozens of different mobile devices. Trying to check for each one in your code is not easy (and probably not worth the trouble).

    cbrack, please do not post links to that site here. There are better resources elsewhere. I recommend you read this: W3Fools: A W3Schools Intervention
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0
    Great, suspicions confirmed, thanks !
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0
    However ~ I suppose .UserAgent used in a post-load js may be useful to determine mobile device or not, and then perhaps dynamically setting the <meta tag scale so that pinch/zoom is disabled ??
  14. #8
  15. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,129
    Rep Power
    4304
    Why would you need to set the <meta name="viewport"> tag dynamically?

    Disabling zoom is very user-unfriendly -- I hope you'd have a very good reason for doing so. What's the smallest touchscreen device you've spent a significant amount of time using for web browsing?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0
    Yes, I understood disable zoom on an iPhone (for example) for a responsive web design was best practice.
  18. #10
  19. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,129
    Rep Power
    4304
    Best practice? No, disabling zoom is very bad practice.

    I recommend you read this: http://blog.javierusobiaga.com/stop-...il-you-know-ho

    For apps and web apps, you might well want to disable it, but for responsive design, it's a very bad idea to do so.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo