[英]Using screen.width to detect tablets in JavaScript
I'm trying to detect if the client is using a tablet in JavaScript. 我正在尝试检测客户端是否在JavaScript中使用平板电脑。 I do not want to use CSS3 or UserAgents if I can.
如果可以,我不想使用CSS3或UserAgents。 One method that came into my mind was using
screen.width
property inside the browser to get the device width and detect tablets if the screen.width
is less than a certain threshold. 我想到的一种方法是在浏览器中使用
screen.width
属性获取设备宽度,并在screen.width
小于特定阈值时检测平板电脑。
Do you guys think this would be a good solution? 你们认为这将是一个很好的解决方案吗?
What is the support for this property? 这个财产有什么支持? Do most tablets support this feature?
大多数平板电脑都支持此功能吗?
Any feedback would be appreciated. 对于任何反馈,我们都表示感谢。
I dont't think you are going to achieve what you want with this approach. 我认为您不会通过这种方法实现您想要的。 If you really wanna do this with only javascript and no "magic way" (CSS3, UserAgents, etc ...), I suggest you to simple add a "switch button" just like language buttons ... something like "Switch to view : tablet / desktop".
如果您真的想只使用JavaScript而没有“魔术”方式(CSS3,UserAgents等),建议您像语言按钮一样简单地添加一个“切换按钮”,例如“切换至视图” :平板电脑/台式机”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.