How to Detect iPad and Redirect to iPad Version Website

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.

<script type="text/javascript"> // <![CDATA[
	if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
		document.location = "";
	} // ]]>


55 thoughts on “How to Detect iPad and Redirect to iPad Version Website”

  1. Say I have a redirect on my iPhone or iPad but they do not want to use it? How can i get them back to the normal web viewing mode?

    Thanks, if you can email me with a reply that would be great!

  2. I think i may write a post about how to do that, check back in a little bit to see if I have one written.


  3. Simple…

    Just Make a copy of the page (add the number 1 to the name) that is redirecting them to the iPhone/iPad Version, but just remove the redirection script.

    So the Link that takes them back to the ‘normal’ viewing mode is to the page WITHOUT the redirection script, enabling them to view your site ‘normally’

    Try that!

  4. Jalen, I think the best way out would be to include a button in the iPhone/iPad version of the site, with something like “take me to the desktop version of this website”, which redirects you to an exact copy of the website but without the device detection code in the files. I understand this is something similar to how Facebook does it on their mobile device version, possibly?
    Thank you so much for sharing this code! It’s exactly what I needed.

Comments are closed.