http://rog.ie/blog/html5-boilerplate-addon A handy snippet I use on all my projects to target specific user agents/mobile devices to fix finicky browser issues.
This is really clever, and it's especially useful for Modernizr's undetectables.
That said, in many cases it's simpler and more reliable to detect features, adjust for screen size, or simply accept that browsers render some elements differently (e.g, text). This is particularly true if the browser fixes the bug that you're working around, and suddenly the workaround becomes the cause of a problem rather than the solution. I worry that this approach is so convenient that it could encourage people to use UA sniffing when a better solution is available.
I'd add that not all cross-browser differences are bugs. Sometimes various standards-compliant browsers interpret the standards in slightly different ways, or add little features on top of the standards.
To me, user agent sniffing is a last resort (see this article for more on why). That said, if you have to do it, you might as well use a clever tool like this one. :)
brilliant! are there any potential downsides to this technique though? is data-useragent* behaviour slower to compute for the browser or plainly negligible?
Alex, that's the only downside I could possibly think of. Attribute selectors on large strings could get unwieldy, however I've used this technique for well over 2 years, but mostly on websites not webapps.
is there a comprehensive / up to date user agent list to be found anywhere?
Alex, not sure, but you could always inspect element on the browser of your choice to see what it reports or open the console and slam in navigator.userAgent
This is incredible! Thanks Rogie. :)
Woah! Nice one! Thanks a lot!
Nice one Rogie!
This is brilliant! Thank you!
Rogie, you're a genius.