Detect phone vs tablet

后端 未结 9 839
别跟我提以往
别跟我提以往 2020-12-16 11:08

Is there a way to detect if the user is using a tablet or a phone? As an example a person surfing the web using a tablet (any android tablet with version 3+ and iPad) they

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 11:55

    If you're using media queries in theory you could use @media handheld but support is pretty much non-existent.

    Simplest way of identifying high res mobile devices would be to look at the DPI of the screen and the device-pixel-ratio (via webkit/mozilla vendor specific tags currently)

    @media (-webkit-max-device-pixel-ratio: 2),  
    (max--moz-device-pixel-ratio: 2), 
    (min-resolution: 300dpi) {
       ...
    }
    

    edit: window.devicePixelRatio to do the above in JS

    There is a nice article here with lots of ideas for identifying mobile devices.

    http://davidbcalhoun.com/2010/using-mobile-specific-html-css-javascript

提交回复
热议问题