5 ms·
"In general, our advice is to develop a responsive site that can adapt to the capabilities of different devices. If you choose to build a mobile-specific experi
by iron_ball 12y ago
"In general, our advice is to develop a responsive site that can adapt to the capabilities of different devices. If you choose to build a mobile-specific experience then we recommend looking for the sub-string "mobile" in the user agent string to determine when to deliver mobile optimised content:"
function isMobile() {
return navigator.userAgent.toLowerCase().indexOf("mobile")>=0;
}
This is really the best we can do after twenty years of the WWW?
- recursive 12y agoBrowser identification is an arms race. It harkens back to the original user agent wars near the turn of the millenium. I think it's unlikely to ever have a solid way to identify browsers. If one is developed, it will be used by (bad?) developers as an exclusion check for their fancy content. That gives other browsers an incentive to lie. I think the whole concept is inherently unstable for this reason.
- misterbwong 12y agoNo. Feature detection (which is also mentioned in the article) is far superior
- woogley 12y agoug, that's already a bad check, but if they insist, why not just: /mobile/i.test(navigator.userAgent)
- masklinn 12y agoI'd add \b around to avoid matching e.g. `Immobile/1.0`, the slow browser.
- Cthulhu_ 12y ago> Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Just because the API call and syntax is a bit iffy doesn't mean it's a bad pattern. ES6 will finally have a string .contains method btw (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/contains https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...)
- virtualwhys 12y agoor do user-agent detection server-side against database of (mostly) known user-agents and take JS out of the UA detection picture entirely. In JVM land I've had pretty good success with UADetector [1] for delivering device specific content to mobile phones and desktop/laptop/tablets. [1] https://github.com/before/uadetector https://github.com/before/uadetector