Using Modernizr to test for tablet and mobile - Opinions wanted

前端 未结 4 800
迷失自我
迷失自我 2020-12-02 18:37

I want to use Modernizr to detect whether a user is view a site on a desktop, tablet or mobile device.

My initial first thoughts are obviously to check screen sizes

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 19:05

    Modernizr can check for touch events

    For testing whether the device is a tablet or phone or desktop, I would probably lean more toward using User Agents. Take a look at the scripts on DetectMobileBrowsers.com

    Modernizr simply tests for whether or not a browser supports certain features. As far as I know, it doesn't appear to test browser_type == mobile and stuff along those lines...

    Keep in mind that a lot of modern desktop PCs these days have touch screens, so even detecting touch support does not guarantee that it is a mobile device or tablet.

提交回复
热议问题