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

This question already has an answer here:

  • What is the best way to detect a mobile device in jQuery? 49 answers

  • 浏览器嗅探似乎是解决方案

    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

    上一篇: 我可以安全地限制访问我的移动网站上的桌面用户吗?

    下一篇: 在JavaScript中检查是否返回智能手机?