A check in JavaScript that returns whether I am on a smartphone?

<>

This question already has an answer here:

Answers


Ye olde browser sniffing seems to be the solution

if( navigator.userAgent.match(/Android/i)
 || navigator.userAgent.match(/webOS/i)
 || navigator.userAgent.match(/iPhone/i)
 || navigator.userAgent.match(/iPad/i)
 || navigator.userAgent.match(/iPod/i)
 || navigator.userAgent.match(/BlackBerry/i)
 ){
 // some code..
}

You could try twitter bootstrap, http://twitter.github.com/bootstrap/scaffolding.html. In particular the Responsive design section.


You can use the Categorizr JS library to test whether the user's device is a mobile phone, a tablet, a smart tv or a desktop. Categorizr uses user agent sniffing, so you should keep an eye out for updates to the script, as user agents tend to "evolve" over time.

Here's how you would use Categorizr to check if the user is on a smartphone, but not a smart TV, a desktop or a tablet:

if (categorizr.isMobile) {
    //run this code if on a phone
} else {
    //run this code if not on a phone
}

Need Your Help

Performance monitoring/profiling for python server process (similar to New Relic)

python performance profiling celery newrelic

Is there a tool/service that can automatically and perpetually instrument and profile python server processes? I'm thinking about processes like Celery or RQ workers? I'd like to get method-level

GridBagLayout format error. JTextFields in wrong positions

java swing jtextfield layout-manager gridbaglayout

I simply cannot get my JTextFields to align correctly. Right now the program looks like this: