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

后端 未结 4 1642
有刺的猬
有刺的猬 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:56

    One way to do it is to check the user agent.

    var UA = navigator.userAgent;
    if (UA.indexOf("iPad") != -1) {
        // iPad
    } else if (UA.indexOf("iPhone") != -1) {
        // iPhone
    }
    

提交回复
热议问题