A check in JavaScript that returns whether I am on a smartphone?
This question already has an answer here:
浏览器嗅探似乎是解决方案
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
}
链接地址: http://www.djcxy.com/p/84054.html