Javascript 仅直接移动设备而非平板电脑
我有一行代码可以检测所有触摸设备:Javascript 仅直接移动设备而非平板电脑,javascript,jquery,device-detection,Javascript,Jquery,Device Detection,我有一行代码可以检测所有触摸设备: <script>if( 'ontouchstart' in window ) window.location = 'mobile.html';</script> if('ontouchstart'在window中)window.location='mobile.html'; 我只想修改它,使其只针对支持触摸的移动设备,但也不包括平板设备。如何在不太具体的情况下做到这一点?如果您想将用户重定向到您的移动站点,请使用以下方法: if (
<script>if( 'ontouchstart' in window ) window.location = 'mobile.html';</script>
if('ontouchstart'在window中)window.location='mobile.html';
我只想修改它,使其只针对支持触摸的移动设备,但也不包括平板设备。如何在不太具体的情况下做到这一点?如果您想将用户重定向到您的移动站点,请使用以下方法:
if (screen.width <= 768) {
window.location = "mobile.html";
}
var is_touch_device = 'ontouchstart' in document.documentElement;
var viewport = $(window).width()
if (is_touch_device == true && viewport < 768) {
(Code goes here)
}
if(screen.width)这可能会有所帮助