问题描述
我发现这个JavaScript来检测BlackBerry设备:
I found this javascript to detect blackberry devices:
<script type="text/javascript">
var ua = navigator.userAgent;
if (ua.indexOf("BlackBerry") >= 0) {
if (ua.indexOf("Version/") >= 0) { // ***User Agent in BlackBerry 6 and BlackBerry 7
Verposition = ua.indexOf("Version/") + 8;
TotLenght = ua.length;
document.write("Jorgesys BB OS Version :: " + ua.substring(Verposition, Verposition + 3));
}
else {// ***User Agent in BlackBerry Device Software 4.2 to 5.0
var SplitUA = ua.split("/");
document.write("Jorgesys BB OS Version :: " + SplitUA[1].substring(0, 3));
}
}
</script>
但需要针对特定的黑莓手机所支持的:
BUT need to target specific BlackBerry's that are supported:
黑莓:
9630结果
9700结果
8900结果
9000
Blackberry:9630
9700
8900
9000
这是可能的,只是针对那些黑莓??
Is this possible to target just those Blackberry's ??
感谢!
推荐答案
是每个代理商都有它的黑莓版本。
Yes each agent has it's blackberry version.
例如:结果 ** ** BlackBerry9000 / 5.0.0.93资料/ MIDP-2.0配置/ CLDC-1.1厂商ID / 179
开发者网站上的更多信息。结果
<一href=\"http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862?IID=DEVSF30\" rel=\"nofollow\">http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862?IID=DEVSF30
More information on the developers website.
http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862?IID=DEVSF30
用一个简单的正则表达式来获取版本了。
use a simple regex to get the version out.
<script type="text/javascript">
var ua = "BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179";
var match = ua.match(/^BlackBerry[0-9]*/);
console.log(match[0]);
var ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/X.X.X.X Mobile Safari/534.11+";
var match = ua.match(/BlackBerry\s[0-9]*/);
console.log(match[0]);
var ua = "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+";
var match = ua.match(/RIM Tablet OS\s[0-9].[0-9].[0-9]/);
console.log(match[0]);
</script>
这篇关于针对特定的黑莓与用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!