Skip to content

Instantly share code, notes, and snippets.

@chssweb
Created August 21, 2012 11:19
Show Gist options
  • Save chssweb/3414641 to your computer and use it in GitHub Desktop.
Save chssweb/3414641 to your computer and use it in GitHub Desktop.
iPhone and iPad sniffer & redirects variations
if (navigator.userAgent && ( navigator.userAgent.indexOf("iPad") > -1 || navigator.userAgent.indexOf("iPhone") > -1 ))
{
window.location.replace("http://www.YOUR-URL-GOES-HERE.com/iPhone-iPad.html");
}
/* change the ‘www.YOUR-URL-GOES-HERE.com” to your site and change the ‘iPhone-iPad.html’ to the name of your iPhone / iPad message or experience.
http://blog.stephengates.com/2010/06/03/easy-iphoneipad-sniffer/
*/
function redirect() {
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
window.location.replace('vr5/iphone.html');
} else if (navigator.userAgent.match(/iPad/i)) {
window.location.replace('vr5/ipad.html');
} else {
if (flashPage == null) {
flashPage = '';
}
if (flashPage.length == 0) {
document.write('<div style="display:block;padding: 1em;margin: 10% auto;border: solid 4px red;background: #f88;color: black;text-align: center;font: bold 18px Arial, Helvetica, sans-serif;width: 80%;">This content requires iPad/iPhone/iPod Touch</div>');
} else {
window.location.replace(flashPage);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment