使用JavaScript检测“触摸屏”设备的最佳方法是什么?

检测“触摸屏”设备的最佳方法是解决文档模型中是否存在触摸方法。

function checkTouchDevice() {
   return 'ontouchstart' in document.documentElement;
}

在这里,您还可以使用它来检测移动设备或桌面设备,如下所示-

if (checkTouchDevice()) {
   //行动装置
} else {
   //桌面
}
猜你喜欢