我有这行代码可以检测所有触摸设备:
<script>if( 'ontouchstart' in window ) window.location = 'mobile.html';</script>
我只想修改它,使其仅针对支持触控的移动设备,但也不包括平板电脑设备。如何做到这一点而不是太具体?
答案 0 :(得分:4)
如果您想将用户重定向到移动网站,请使用以下命令:
if (screen.width <= 768) {
window.location = "mobile.html";
}
如果你想知道它的触摸屏是否小于768px,我认为你可以使用它:
var is_touch_device = 'ontouchstart' in document.documentElement;
var viewport = $(window).width()
if (is_touch_device == true && viewport < 768) {
(Code goes here)
}