Check BlackBerry OS version
Asked Answered
T

2

1

How do I get the BlackBerry OS version via javascript or jquery in a Webworks app?

I tried the following code from a thread "detect blackberry os version" but it isn't working for me:

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';
}
Turkey answered 7/6, 2011 at 8:44 Comment(1)
Since adopting feature/capability detection sometime early last decade I've forgotten all about userAgent strings. What are they used for again?Tichonn
P
3

based on this document...

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862

<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>
  • be sure to have Javascript Enabled! =)
Paperweight answered 8/6, 2011 at 22:48 Comment(6)
:((, your code displays nothing on my simulator. any answers pls.Turkey
Yep by using this instructions: Go to Browser->Options->Browser Configuration->Scroll down->Enable "Support JavaScript"->Save Options; and it doesn't work, :(( mommyyy..Turkey
i have tested this script in several devices, OS versions, mmm do you have the link of your .html page?Paperweight
it works with my blackberry simulator's browser, but when integrating it with my webworks app, it just destroys everything. any help?Turkey
Finally, It seem like the code above works!, yeah... tnx jorgesys.Turkey
what was your problem Cache issues?Paperweight
D
1

If you have experienced trouble detecting BlackBerry 10 (as I did after reading this answer!), be aware that the user agent string has changed in BB10, as explained in http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/

In my specific case, I wanted to check if the version was just BB10, for which the next code is enough:

isBlackBerry: function() {
    // Only works with the latest version: BlackBerry 10
    return navigator.userAgent.match(/BB10/i);
}
Dripstone answered 25/9, 2013 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.