www.webdeveloper.com
Results 1 to 10 of 10

Thread: Is window.navigator.userAgent reliable ?

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    12

    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
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    yes, it's reliable. not in a legal sense, since hackers can alter it, but 99.9% of web surfers have no idea what a userAgent is, much less alter it. Only folks who tinker with will cause issues, and it's squarely their fault if that happens.

  3. #3
    Join Date
    Jun 2012
    Posts
    12
    What happens to the value of .userAgent if the user changes the browser config ?

  4. #4
    Join Date
    Mar 2011
    Posts
    1,133
    If the user changes it, that's his choice and he has to accept any consequences. For a web designer, it depends on the reason you're checking this value in the first place. Generally, you should check for specific features and functions rather than rely on the userAgent string anyway since browsers evolve over time and your code can get really convoluted if you try to check for specific versions. And, of course, entirely new browsers are always a possibility.
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Jun 2012
    Posts
    12
    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?

  6. #6
    Join Date
    Mar 2011
    Posts
    1,133
    Your original post didn't explain why you wanted to check the userAgent, so I wasn't sure what you were doing. It's up to you if you prefer to serve a dedicated version of your site to mobile users, and if that's what you decide to do then checking the userAgent string is your only choice. But it's best to handle the redirection at the server level, rather than relying on JavaScript. If you use JavaScript, the user has to load the entire default HTML document first, and some additional files will probably start to be downloaded before that JavaScript gets executed, which wastes the user's time and bandwidth. Some Google searches will show you how to do this at the server level.

    Not every design works well on mobile devices, but you'd be surprised by how often responsive design actually can be used effectively.
    Rick Trethewey
    Rainbo Design

  7. #7
    Join Date
    Jun 2012
    Posts
    12
    Thanks Rick, serious food for thought !

  8. #8
    Join Date
    Jun 2012
    Posts
    12
    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 ??

  9. #9
    Join Date
    Mar 2011
    Posts
    1,133
    Of course, these are all design choices that come with every website. I'd just suggest that you keep in mind that you don't have to use the same page layout on every platform to present your content. If you build your sites with some basic responsive design features like using '%'s and 'em's for sizing and positioning, even if you don't take full advantage of them immediately, you'll make it easier to enhance them over time. You don't have to take the big plunge. You can just dip your toes in the water to see how it feels.
    Rick Trethewey
    Rainbo Design

  10. #10
    Join Date
    Jun 2012
    Posts
    12
    Yeah, makes sense, thanks Rick

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles