Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Blackberry Browser on google Sites

I'm using google calendar embedded on a Google Site.

BlackBerry users are reporting errors so I want to redirect them to another page.

I tried to add this code

<script type="text/javascript">   
   var ua = navigator.userAgent;
   var url = "http://optimizedmobile.yoursite.com/";
   if (ua.indexOf("BlackBerry") >= 0)
   {
      if (ua.indexOf("WebKit") >= 0)
      {
         window.location = url;
      }
   }
</script>

using the instructions provided here, but it's not working. I tested the code in a html file that I created and it works.

So, any other ideas to include the code on the page? Do you think the code is not supported by Google sites?

Any other ideas to redirect BB users?

like image 688
Juanma Baiutti Avatar asked Dec 04 '25 03:12

Juanma Baiutti


1 Answers

I don't know exactly which BlackBerry devices you're trying to detect. Unfortunately, the answer is different for many of them.

From this BlackBerry.com reference document, some UserAgent examples:

User Agent in BlackBerry 10

Mozilla/5.0 (BB10; <Device Type>) AppleWebKit/537.10+ (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/537.10+

User Agent in BlackBerry Tablet OS

Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.0.0; en-US) AppleWebKit/535.8+ (KHTML, like Gecko) Version/7.2.0.0 Safari/535.8+

User Agent in BlackBerry 6 and BlackBerry 7

Mozilla/5.0 (BlackBerry; U; BlackBerry AAAA; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/X.X.X.X Mobile Safari/534.11+

User Agent in BlackBerry Device Software 4.2 to 5.0

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

So, it looks to me like the exact string BlackBerry will only show up in user agents for devices with Java OS version 4.2 - 7.1. And, among those, only those with OS 6.0 - 7.1 will be using the WebKit browser.

So, I think you just need to add some more cases to your if statement, to detect all BlackBerry devices.

like image 137
Nate Avatar answered Dec 06 '25 16:12

Nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!