繁体   English   中英

我的“ isMMobile()”功能正在将桌面用户代理检测为移动

[英]My “isMMobile ()” function is detecting desktop user agent as mobile

这是什么设备? 我的功能是将此设备检测为移动设备

“像Gecko一样的Mozilla / 5.0(Windows NT 6.1; Trident / 7.0; rv:11.0)”

function isMMobile() {

    var device_agent = navigator.userAgent.toLowerCase();
    if (/android|webos|iphone|ipad|ipod|blackberry|windows phone|opera mini|iemobile|tablet|nokia|kindle|mobile/i.test(device_agent)) {
        return true;
    }

    if (window.DocumentTouch && document instanceof window.DocumentTouch) {
        return true;
    }

    if (typeof window.orientation === "number" || 
        'ontouchstart' in window || 
        window.ontouchstart || 
        'ontouchstart' in document.documentElement || 
        "ontouch" in window || 
        window.onmsgesturechange || 
        window.navigator.msMaxTouchPoints || 
        window.navigator.MaxTouchPoints > 0) {
        return true;
    }

    return false;
}

var innerw = window.innerWidth || document.documentElement.clientWidth;
var ismob = isMMobile();

通过ajax发送的数据:

ismob=yes&innerw=800

那是Windows 7上带有触摸屏的IE 11。 现在,大多数Windows笔记本电脑都具有触摸功能(并且有一段时间),因此,如果您的逻辑基本上是“触摸==移动”,那么您会误认很多设备。 那里有很多移动检测脚本,这也很有用,因为其他人必须跟上新的用户代理和设备。 如果可以的话,让他们处理检测中的头疼问题!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM