SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you are targeting key devices then it would be but a quick search of Google reveals several ways to accomplish device detection.

    https://www.google.com/search?q=mobi...hrome&ie=UTF-8

  3. #3
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not very enlightening, what happens to the value of .userAgent if the user changes the browser config ?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The useragent can be set to anything at all by the person who owns the browser. Firefox, chrome and Opera provide options to make this easier (to change it for IE you need to update the Registry). In Opera you can even set it up to present different useragent values to different web pages.

    Since most people don't change it you can rely on its value for gathering statistics but you can't rely on it for anything else.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Since most people don't change it you can rely on its value for gathering statistics but you can't rely on it for anything else.
    Google Maps is an example that relies on it entirely. When I loaded it using a blank UA, it slandered the capabilities of what was at the time the current FireFox.
    Tab-indentation is a crime against humanity.

  6. #6
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have a site with a large and cluttered content area, which is probably ok on a desktop/laptop, surely a responsive design will look rediculous on a smartphone with tiny viewport. In this scenario surely a simplified, optimised design would be better, ie user gets redirected to a separate site for mobile devices. In this case isn't device detection necessary to effect the redirect?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jonatec View Post
    If you have a site with a large and cluttered content area, which is probably ok on a desktop/laptop, surely a responsive design will look rediculous on a smartphone with tiny viewport. In this scenario surely a simplified, optimised design would be better, ie user gets redirected to a separate site for mobile devices. In this case isn't device detection necessary to effect the redirect?
    The best way to do device detection is by using media queries to check the viewport size. That way you can use a page layout that will fit the browser viewport regardless of what device it is. It is trivially easy to set up almost any browser on a computer so it has the same viewport size as a mobile device and reports the same useragent as that mobile device so that you have no way to teoll that it is actually being viewed on the computer and that the person doesn't even own the device it claims to be.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that.

    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 ??


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •