Wednesday, July 02, 2008

Script to Detect iPhone and Blackberry

The most visited post at is my scripts for how to detect if a visitor is hitting your site with a mobile phone and redirect them to a mobile friendly version of this website (at

I have received a lot of emails asking how we can modify this script to detect iPhones or Blackberry browsers. For the most part, the script is identical.

First, the original script-

With the iPhone, it is fairly simple. in your "if" string, include the following:

if((navigator.userAgent.match(/iPhone/i)) (navigator.userAgent.match(/iPod/i)))

A Blackberry is a little more challenging as you can have different browsers. For example, I am using Opera Mobile on my Blackberry Pearl. With a Blackberry, the browser detect in the first script should work, however, Opera Mobile reformats the page automatically and thus, the script shouldn't be needed.

I am currently experimenting with several other browser options. I'll add a new post as I discover more scripts to help your mobile learners.

No comments: