使用用户代理定位特定的黑莓手机

发布于 2024-12-11 19:51:53 字数 806 浏览 0 评论 0原文

我发现这个 javascript 可以检测黑莓设备:

<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>

但需要针对受支持的特定黑莓:

黑莓: 9630
9700
8900
9000

这可以只针对那些黑莓吗?

感谢!

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:

Blackberry:
9630
9700
8900
9000

Is this possible to target just those Blackberry's ??

Thank!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李不 2024-12-18 19:51:53

是的,每个代理都有其黑莓版本。

示例:
**BlackBerry9000**/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179

有关开发人员网站的更多信息。
http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862?IID=DEVSF30

使用简单的正则表达式来获取版本。

<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>

Yes each agent has it's blackberry version.

Example:
**BlackBerry9000**/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文