HTML and CSS Reference
Although this might seem like a good idea, it is fraught with problems and you
must be careful. First, you'll have to publish and maintain two or more versions
of your site (desktop version, mobile version, iPad app, TV app, etc.), which adds
more time and cost to the project.
Second, doing browser sni ng is error prone and shortsighted. If you are just
detecting the iPad, for example, because you have a specific iPad app, it might
not be so bad. But it usually makes more sense to develop sites to work across all
devices, not just one. Also, user agent strings are deliberately ambiguous, because
back in the early days of the web, developers started using user agent sni ng to
arbitrarily target browsers they wanted to support, leaving other browsers locked
out, even if they could render those sites perfectly well. To get access to these sites,
browsers started aping other vendors' user agent strings, so you'd end up with
user agent strings like this:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13
p (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
And even if your code is serving the right content to the right browsers now, it
may not in the future when new browsers come out that have different user agent
strings. You'll have to keep updating your code to take these new browsers into
account! As an example, when Opera hit version 10, the user agent string was
changed to include a version number of 9.81, because so many developers were
using browser sni ng code that returned Opera 10+ as Opera 1, thereby blocking
browsers from accessing sites that would render them fine. Hilarity ensued. Really.
It is much more effective and less error prone to test whether browsers support
the features your sites need, as you've been doing with Modernizr, rather than
testing whether the browser is one of the ones you think will support your code.
TIP: Yo u s h o u l d a l way s p r o v i d e a l i n k t o s w i t c h b e t w e e n s i t e
versions too, in case a mobile user wants to use the desktop
version of the site instead. Users hate having their choices taken away!