Sim*_*ain 5 javascript google-chrome
我知道很多JavaScript库依赖于"ontouchstart"来检测它是在平板电脑还是桌面上.
这是我正在谈论的代码示例:
var hasTouch = ("ontouchstart" in window);
Run Code Online (Sandbox Code Playgroud)
目前,我不得不注释掉所有平板电脑检测代码才能正常工作.
检测平板电脑与台式机的最佳方法是什么?
谢谢!
小智 3
为了看看它是否是一个移动平台,我用过这个
var iPadAgent = navigator.userAgent.match(/iPad/i) != null;
var iPodAgent = navigator.userAgent.match(/iPhone/i) != null;
var AndroidAgent = navigator.userAgent.match(/Android/i) != null;
var webOSAgent = navigator.userAgent.match(/webOS/i) != null;
var isMobile = iPadAgent || iPodAgent || AndroidAgent || webOSAgent;
Run Code Online (Sandbox Code Playgroud)
它运作得很好。
| 归档时间: |
|
| 查看次数: |
480 次 |
| 最近记录: |