O'Reilly logo

BlackBerry Hacks by Dave Mabe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #87. Detect BlackBerry Browser Requests the Right Way

Examine the headers of an HTTP request to determine what content is best suited for the browser making the request.

Let's say you've decided to have different versions of the content on your web site for desktop browsers than for the BlackBerry Browser. What is the best way to make these versions available to your users? You could make the different versions available at different URLs. For example, http://www.site.com would be for regular browsers while http://wap.site.com would be your URL for WAP browsers. While this approach certainly works, it forces your users to remember two different URLs for essentially the same content. It would be more convenient to use a single URL for your site and have your web application determine the content that should be provided, depending on the browser making the request. How can you check to see what type of browser is making a request to your web application?

There is a right way and wrong (read: easy) way to do this in your application. The good news is that the wrong way is okay to do in certain situations. There are two different HTTP headers that are available to your web application to help determine the browser type: HTTP_USER_AGENT and HTTP_ACCEPT.

The Old Way

The HTTP_USER_AGENT,or user agent string, is used by browsers as a way of advertising their browser type. This string has information about that identifies the browser and version along with general details about your operating ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required