What's the best way to detect whether the client is a tablet or a phone?

后端 未结 4 1744
有刺的猬
有刺的猬 2021-01-22 20:24

I am currently developing a client side application which will be designed for both, smartphones and tablets. Therefore it will get two different layout modes.

While th

4条回答
  •  不要未来只要你来
    2021-01-22 20:43

    +1 for testing screen resolution rather than user agent (and iPhone vs iPad is a very simplistic test anyway—what about all those other tablet devices??)

    In terms of testing for iPhone 4, i.e. retina displays, this test should work in your Javascript:

    if(window.devicePixelRatio > 1){
        // Retina device...
    

提交回复
热议问题