根据Paul Irish 的说法,RIM关于这个问题是这样说的:
不幸的是,我们在 BlackBerry 6.0 期间遇到了构建系统问题,导致构建启用了 WebKit 触控支持,即使对于非触控设备也是如此。它早就被修复了,但一些公共版本确实存在这个问题。
在 github/Modernizr 上查看这些(当前打开的)票证,了解可能的解决方法和最新的检测代码,然后尝试根据需要更改您的插件。如果下面的最新检测代码不起作用,您可能需要专门检测黑莓。
还要检查此触摸测试,browserscope 选项卡表明黑莓 9000 已被检测为错误,因此也值得在您的设备中进行测试。http://modernizr.github.com/Modernizr/touch.html
触摸检测的最新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;
};
黑莓/PlayBook UA 嗅探
为了使用用户代理字符串专门检测 BlackBerry 设备并从此处和此处提供的解决方案中借用,我启动了这个小功能,您可以在http://jsbin.com/aliwur/1/edit#上测试并查看在 jsbin 上的工作情况javascript,live它应该从用户代理字符串中解析出 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/