简体   繁体   English

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

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

What's this device? 这是什么设备? My function is detecting this device as mobile 我的功能是将此设备检测为移动设备

"Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" “像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();

Data sent via ajax: 通过ajax发送的数据:

ismob=yes&innerw=800

That is IE 11 on Windows 7, with a touchscreen. 那是Windows 7上带有触摸屏的IE 11。 Most windows laptops now have touch (and have for a while) so if your logic is basically “touch == mobile” then you will misidentify a lot of devices. 现在,大多数Windows笔记本电脑都具有触摸功能(并且有一段时间),因此,如果您的逻辑基本上是“触摸==移动”,那么您会误认很多设备。 There are a lot of mobile detection scripts out there, which also helps because someone else has to keep up with the new user agents and devices. 那里有很多移动检测脚本,这也很有用,因为其他人必须跟上新的用户代理和设备。 If you can, let them deal with the headaches in detection! 如果可以的话,让他们处理检测中的头疼问题!

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

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