Browse - Programming Tips - Is there a modern/simple way to check for a mobile brower?

Date: 2014dec5
Language: php, perl

Q.  Is there a modern/simple way to check for a mobile brower?

A.

This page suggests just looking for "Mobi"
https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
And it makes sense to me.

In javaScript:

function isMobile() { return navigator.userAgent.indexOf('Mobi') >= 0; }
In PHP:
function isMobile() { $useragent = $_SERVER['HTTP_USER_AGENT']; return strpos($useragent, 'Mobi') !== false; }
In Perl:
sub isMobile() { my $agent = $ENV{HTTP_USER_AGENT}; return $agent =~ m/Mobi/; }
In Java Servlet:
boolean isMobile(HttpServletRequest request) { final String agent = request.getHeader("User-Agent"); if (agent == null) return false; return agent.indexOf("Mobi") >= 0; }