iPad detection the right way

iPad in action

The famous large flat thing slightly more useful than a rock

Here at Konstellation, we just launched the PageGangster for mobile devices including iPad, iPhone, iPod touch and Android. I developed the clientside for this in JavaScript and we launched it with automatic user agent detection serverside. But this had some problems.

I read some info about this and conclude, that some iPad user agent strings include the word “iPhone” and some users of all types of devices fake their user agent strings.

But then I read on the above link, that no matter what, the navigator.platform attribute would always be set to the right type of device. So in the regular web version of the publication viewer we have now (which uses Flash), we have added a JavaScript detecting if the serverside script did not redirect the client properly:

if (navigator && navigator.platform && navigator.platform.match(/^(iPad|iPod|iPhone)$/)) {
	location.replace(location.href+"?force-mobile");
}

It seems simple, but solves the problem of some users seeing the dreaded blue box instead of their publication optimized for their device.

On another node, this experience of developing a web application for the iPad/iPhone was very rewarding and I gained many insights, which might spawn other posts. And if you have any questions about it in any way, feel free to ask here – but please do not submit bug reports about the PageGangster for mobile – do that via info@pagegangster.com instead.

No related posts.

Category: JavaScript, Konstellation, Regular Expressions, Trends 3 comments »

3 Responses to “iPad detection the right way”

  1. Rune Bromer

    They might even use support@pagegangster.com.

  2. iPad support adding on pagegangster.com « bromer

    [...] regular HTML and javascript. In my¬†opinion¬†this is why it’s so cool. As you can read on Morten Barklunds blog we detect the user agent and display a range of converted [...]

  3. Lars W

    Du er kongen Morten .. as always :-)


Leave a Reply



Back to top

     

Get Adobe Flash playerPlugin by wpburn.com wordpress themes