Menu

How to Detect iPad and Redirect to iPad Version Website

September 16, 2011 - Uncategorized

With all the buzz about the iPad, I wanted to post another useful snippet of code. It detects whether the person viewing your website is on a iPad. If they are on a iPad, you can redirect them to a iPad version website or just to another page, its up to you. If they are on a normal computer it doesn’t redirect them and they go on as normal. Its just some simple javascript, and if you want to use it just change the “document.location” value to the url you want them redirected. Here is the code, and its just the same as when you detect for the iPhone with an extra argument.

[sourcecode language=”js” light=”false”]
<script type="text/javascript">
if ((navigator.userAgent.indexOf(‘iPhone’) != -1) ||
(navigator.userAgent.indexOf(‘iPod’) != -1) ||
(navigator.userAgent.indexOf(‘iPad’) != -1)) {
//redirect to iOS version
document.location = "http://www.sorlo.com/ipad";
}
</script>
[/sourcecode]