www.webdeveloper.com
Results 1 to 4 of 4

Thread: Blackberry redirect?

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    8

    Blackberry redirect?

    Hi everyone. I'm trying to find some script to redirect Blackberries to our mobile site automatically. I found some javascript that works for iPhones - it just reads the screen width (<=699) and redirects with document.location="http://www.mymobilesite.htm". But this doesn't work with Blackberries. Here's the statement I'm trying.

    <script type="text/javascript">
    <!--
    if ((screen.width <= 800) || (navigator.useragent.match(/blackberry/i)) {
    document.location = "mypageurlhere.htm";
    }
    //-->
    </script>

    I'd heard that Blackberries don't read javascript at all, but I found this code out there - plus the Blackberry site says that useragent detection in javascript should work! Maybe it's just a syntax error?

    I'm not working with PHP or anything fancy and good, just HTML.

    So I'm baffled. If it's just plain impossible, how come no one seems to say that either?

    Thanks everyone. Hope someone can help.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    <script type="text/javascript">
    onload=function(){
    if ((screen.width <= 800) || (navigator.userAgent.match(/blackberry/i)) {
    window.location.href = "mypageurlhere.htm";
    }
    }
    </script>
    But for Blackberry in WAP/WML modes, the code above might not work, as I believe that in those cases JavaScript is disabled. Or if the JavaScript is disabled you can not use a JavaScript code, can you?

    A server-side solution looks more reliable.

  3. #3
    Join Date
    Dec 2009
    Posts
    8

    Thanks, but no luck. How about this?

    Sigh. Yeah, I think most Blackberries either have javascript disabled or don't have it at all. I'll try a server-side solution - I think there's a PHP page I can get to to put an all-purpose redirect on.

    Speaking of which, do you (or does anyone) know some good code for that? I've found a few solutions - one is to stick something like this in the .htaccess file:

    1.#redirect mobile browsers
    2.RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
    3.RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
    4.RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
    5.RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
    6.RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
    7.RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]

    or put something like this in a destination PHP page:

    <?php

    $mobile = “YOUR MOBILE SITE HERE”;
    $text = $_SERVER['HTTP_USER_AGENT'];
    $var[0] = ‘Mozilla/4.’;
    $var[1] = ‘Mozilla/3.0′;
    $var[2] = ‘AvantGo’;
    $var[3] = ‘ProxiNet’;

    ...and so forth with more variable strings for various useragents then...

    $result = count($var);

    for ($i=0;$i<$result;$i++)
    {
    $ausg = stristr($text, $var[$i]);
    if(strlen($ausg)>0)
    {
    header(“location: $mobile”);
    echo ‘<BR>mobile device detected<BR>’;
    break;
    }

    }
    ?>

    Which solution is better? Or is there some other way?

    Thanks!

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    any server-side solution (either .htaccess or php) is definitely the best solve.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles