Using Modernizr to test for tablet and mobile - Opinions wanted

前端 未结 4 794
迷失自我
迷失自我 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 18:58

    This question is a bit old but I couldn't find a better answer when I googled it.

    Most desktops now are touch enabled, so detecting it is irrelevent.

    The best way to detect them is by screen size.

    With Modernizr you can use if (Modernizr.mq('only all and (max-width: 480px)')) { ...}

提交回复
热议问题