javascript - 触摸检测黑莓9300 6.0

标签 javascript jquery html mobile blackberry

我目前在使用的插件中遇到一些触摸检测问题。

插件使用如下代码

touch = ("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch;
eventType = (touch) ? "touchend" : "click";

确定是否应该在某些图库导航上使用 touchend 或 click 事件。

但是不幸的是,当使用运行 os 6.0 的黑莓 9300 访问该页面时,它被错误地报告为支持触摸的设备并且事件没有触发。

我检查了使用的检测方法,它与Modernizr中的相同。

有人能解决这个问题吗?

最佳答案

根据 Paul Irish, RIM said关于这个问题:

Unfortunately, we had a build system issue during BlackBerry 6.0 that caused builds to have WebKit touch support enabled, even for non-touch devices. It's long been fixed, but some public builds do have this issue.

在 github/Modernizr 上查看这些(当前打开的)票证,了解可能的解决方法和最新的检测代码,然后根据需要尝试更改您的插件。如果下面的最新检测代码不起作用,您可能需要专门检测黑莓。

同时检查 this touch test out,browserscope 选项卡指示 blackberry 9000 已被检测为假的,因此也值得一试在您的设备中对其进行测试。 http://modernizr.github.com/Modernizr/touch.html

latest modernizr除了您发布的代码之外,触摸检测的来源似乎还添加了@media 检测。

/*
 * The Modernizr.touch test only indicates if the browser supports
 *    touch events, which does not necessarily reflect a touchscreen
 *    device, as evidenced by tablets running Windows 7 or, alas,
 *    the Palm Pre / WebOS (touch) phones.
 *
 * Additionally, Chrome (desktop) used to lie about its support on this,
 *    but that has since been rectified: crbug.com/36415
 *
 * We also test for Firefox 4 Multitouch Support.
 *
 * For more info, see: modernizr.github.com/Modernizr/touch.html
 */

tests['touch'] = function() {
    var bool;

    if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
      bool = true;
    } else {
      injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) {
        bool = node.offsetTop === 9;
      });
    }

    return bool;
};

BlackBerry/PlayBook UA 嗅探

使用用户代理字符串并借鉴 here 给出的解决方案专门检测黑莓设备和 here我创建了这个小函数,您可以在 http://jsbin.com/aliwur/1/edit#javascript,live 测试并查看在 jsbin 上的工作情况它应该从用户代理字符串中解析出 Blackberry 5.0/4.0/6.0 和 Playbook:

function rim_useragent_parser(ua) {

    var info = false,
        model = null,
        model_number = null,
        os_version = null;

    if (ua.indexOf("BlackBerry") >= 0) {
        if (ua.indexOf("Version/") >= 0) {
            // BlackBerry 6 and 7
            model = ua.match(/BlackBerry\s[0-9]*/);
            if (model) {
                model_number = model[0].match(/[0-9]+/);
                pos = ua.indexOf("Version/") + 8;
                os_version = ua.substring(pos, pos + 3);
                info = {
                    'model' : model[0],
                    'model_number' : model_number[0],
                    'os_version' : os_version
                };
            }
        }
        else {
            // BlackBerry Device Software 4.2 to 5.0
            model = ua.match(/^BlackBerry[0-9]*/);
            if (model) {
                model_number = model[0].match(/[0-9]+/);
                var SplitUA = ua.split("/");
                os_version = SplitUA[1].substring(0, 3);
                info = {
                    'model' : model[0],
                    'model_number' : model_number[0],
                    'os_version' : os_version
                };
            }
        }
    }
    else if (ua.indexOf("PlayBook") >= 0) {
        // PlayBook
        model = ua.match(/RIM Tablet OS\s[0-9].[0-9].[0-9]/);
        if (model) {
            model_number = model[0].match(/[0-9].[0-9].[0-9]/);
            pos = ua.indexOf("Version/") + 8;
            os_version = ua.substring(pos, pos + 5);
            info = {
                'model' : model[0],
                'model_number' : model_number[0],
                'os_version' : os_version
            };
        }
    }

    return info;

}

当然,这可能比您需要的更多,因此将其简化为仅“Blackberry 9300 6.0”我想您也可以这样做:

var ua = navigator.userAgent;
if (ua.indexOf("BlackBerry") >= 0) {
    if (ua.indexOf("Version/") >= 0) {
        // BlackBerry 6 and 7
        var model = ua.match(/BlackBerry\s[0-9]*/);
        if (model) {
            var model_number = model[0].match(/[0-9]+/);
            if (model_number) model_number = model_number[0];
            pos = ua.indexOf("Version/") + 8;
            os_version = ua.substring(pos, pos + 3);

            if (os_version === '6.0' && model_number === '9300') {
                // do what you need specifically for this
            }
        }
    }
}

为了更好的通用用户代理解析,请参阅 ua-parser

https://github.com/tobie/ua-parser/

关于javascript - 触摸检测黑莓9300 6.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11827446/

相关文章:

javascript - 为什么在 Firebase 云函数中没有成功完成 Promise.all() 就退出无服务器函数时性能会下降?

javascript - 无法获取 vars 的值以使用 javascript 动态创建表单

javascript - 使用 jquery 在选中/未选中的复选框上添加/删除值

jquery - 如何使用 jQuery 插件突出显示 DataTable 的过滤文本?

javascript - 是否有任何 JavaScript 库可以读取 .cer 文件并从中获取 key ?

删除 mysql 数据的 Javascript 警报在新选项卡中打开

javascript - Node.js退出时如何释放Oracle数据库连接

javascript - 在一个函数之后设置超时

javascript - 表单数据在新页面中不可见 - PHP + Javascript

html - 垂直居中文本覆盖