Tag Archive | "webapps"

Identify an Apple iPhone, iPod or iPad Visitor to Your Website

Tags: , ,

Identify an Apple iPhone, iPod or iPad Visitor to Your Website


If you run a website and would like to provide specific content to users of iPhone, ipods or iPads there is a simple way to do so:

identify iPhoneThe user agent string can be analyzed on the server or client to determine which device is accessing your site. That said, remember browser sniffing stinks: it’s better to create a single website which works on a variety of browsers than maintain multiple differing versions. However, you could use this code to collate statistics or create alternative view of your web application which matches the iPhone interface.

Posted via web

Here’s some JavaScript detection code:
// Apple detection object
var Apple = {};
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d++) {
	var t = Apple.Types[d];
	Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));
	Apple.Device = Apple.Device || Apple[t];
}
// is this an Apple device?
alert(
	"Apple device? " + Apple.Device +
	"\niPhone? " + Apple.iPhone +
	"\niPod? " + Apple.iPod +
	"\niPad? " + Apple.iPad
);

If you are running a PHP dynamic website you can also use the PHP code below:

// Apple detection array
$Apple = array();
$Apple['UA'] = $_SERVER['HTTP_USER_AGENT'];
$Apple['Device'] = false;
$Apple['Types'] = array('iPhone', 'iPod', 'iPad');
foreach ($Apple['Types'] as $d => $t) {
	$Apple[$t] = (strpos($Apple['UA'], $t) !== false);
	$Apple['Device'] |= $Apple[$t];
}


Related Blogs

Posted in Apple NewsComments (0)


Learn to Make iPad Apps

Facebook