Following on from my post at the weekend about Responsive Design, a fellow blogger Tristan Bettany has emailed in his example for detecting either the iPad or the iPhone and the screen orientation.
It uses a small amount of PHP to detect the device then CSS to detect the orientation. Copy and paste the following into the head of your page.
<?php
//Functions to check user agent for iPad, iPod, iPhone
function iPadCheck(){
return preg_match('/(iPad)/', $_SERVER['HTTP_USER_AGENT']);
}
function iPhoneCheck(){
return preg_match('/(iPhone|iPod)/', $_SERVER['HTTP_USER_AGENT']);
}
//Set correct css files based on detected device
//orientation property supported in mobile safari to change layout on rotation
if (iPadCheck()) {
echo'
<link rel="stylesheet" type="text/css" media="screen and (orientation:portrait)" href="iPadPortrait.css" />
<link rel="stylesheet" type="text/css" media="screen and (orientation:landscape)" href="iPadLandscape.css" />
';
} else if (iPhoneCheck()) {
echo'
<link rel="stylesheet" type="text/css" media="screen and (orientation:portrait)" href="iPhonePortrait.css" />
<link rel="stylesheet" type="text/css" media="screen and (orientation:landscape)" href="iPhoneLandscape.css" />
';
} else {
echo'
<link rel="stylesheet" type="text/css" media="screen and (max-width: 1199px)" href="minDesktop.css" />
<link rel="stylesheet" type="text/css" media="screen and (min-width: 1200px)" href="fullDesktop.css" />
';
}
?>
The script detects the device then includes the associated stylesheet depending on the orientation.
Any questions add a comment.

If you are living in the UK and you have turned your TV on through the day then you will usually not be able to watch 1 hours worth of programs without seeing a bingo advert. From that annoying Fox that used to sponsor The Jeremy Kyle Show, to Barbara Windsor being the face of JackpotJoy, bingo seems to be huge, but is it really and are people actually buying into the TV adverts?


twitter.com/kingpetey
Flickr
LinkedIn
Facebook
Contact me via email
Contact me on Facebook
Contact me on Youtube