Here are a few methods by which you can detect iPad browser.

Given that string we can create a few code snippets to determine if the user is being a smug, iPad-using bastard.

1.The PHP

This time we look for the position of “iPad” in the user agent string.

[php toolbar=”true” classname=”one_line”] $isiPad = (bool) strpos($_SERVER[‘HTTP_USER_AGENT’],’iPad’);
[/php]

2.The JavaScript

A quick String.match regular expression test can check for the presence of “iPad” in the user agent string.

[php toolbar=”true” classname=”one_line”] // For use within normal web clients
var isiPad = navigator.userAgent.match(/iPad/i) != null;

// For use within iPad developer UIWebView
// Thanks to Andrew Hedges!
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);

[/php]

3.Bonus! .htaccess Detection

We can even use .htaccess directives to detect and react to iPad devices!

[php toolbar=”true” classname=”one_line”] RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301] [/php]

And there you have it: three different iPad device detection! Have fun with your mobile development!

Leave A Comment