如何在Webworks应用程序中通过javascript或jquery获取BlackBerry OS版本?
我尝试使用线程“detect blackberry os version”中的以下代码,但它对我不起作用:
var limit = '4.5.0.127';
var version = /BlackBerry\w+\/([\d\.]+)/i.exec(navigator.userAgent);
if (version[1] && version[1] < limit) {
location.href='notcompatible.cfm';
}
答案 0 :(得分:3)
基于此文件...
<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>
答案 1 :(得分:1)
如果您在检测到BlackBerry 10时遇到问题(正如我在阅读此答案后所做的那样!),请注意BB10中的用户代理字符串已更改,如http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/中所述
在我的具体情况下,我想检查版本是否只是BB10,下一个代码就足够了:
isBlackBerry: function() {
// Only works with the latest version: BlackBerry 10
return navigator.userAgent.match(/BB10/i);
}