iPhone Detection and Redirection | iPhone Stuck Pixel and Dead Pixels fix

iPhone Detection and Redirection

iphone browserYes, you can detect when an iPhone or iPod Touch is browsing your website, and direct them to an iPhone friendly version.

Just insert the following code in the header of your page and amend it to address your target (iPhone version) location.

UPDATED – As of iPhone Safari 2, the script isn’t accurate. The new Updated script is here.

Thanks to Chris Bailey at Used Boats for bringing this to attention and re-writing the script for us.

I’ve been irritated seeing websites that say “If you’re using an iPhone, click here” – C’mon, people don’t want to go through that and coders need to anticipate this. Seamless to users and polishes your project.

23 Responses to “iPhone Detection and Redirection”

  1. ShamanG January 25, 2008 at 11:46 pm #


  2. Convent Station Guy January 27, 2008 at 8:54 pm #

    Wow, you and everyone else loves their IPhones. Keep up the great articles, some on IPhones and the traffic will keep knocking down your door.

  3. joe January 30, 2008 at 8:22 pm #

    personally i hate the fact that websites automatically redirect me to a “mobile” version of it. i would rather be asked, or have an option in safari not to send the data saying that its an iphone. “mobile” versions of websites suck, and id rather wait for the bigger ones to load personally. just my opinion.

  4. Knox January 30, 2008 at 8:25 pm #

    Fair opinion Joe- I don’t do it automatically here, but would with some projects. Some sites, especially flash driven sites, won’t render in an iPhone. This sometimes will thwart any type of navigation, so this method allows use of the site instead of appearing dead to the user.

  5. Nathan February 2, 2008 at 9:58 am #

    Your way works better than what I was doing before. :mrgreen: Thanks again!

  6. Knox February 3, 2008 at 2:49 pm #

    No prob, glad it helps.

  7. Charles February 7, 2008 at 9:47 am #

    Thank You for the time you spent adding and testing this code to your blog. 😀

  8. Knox February 7, 2008 at 12:01 pm #

    No problem Charles – your project looks cool too.

  9. Glenn June 17, 2008 at 7:51 pm #

    OMG I have been looking all night for this code. Thanks for posting it.

  10. Shaun July 2, 2008 at 10:51 pm #

    The first one I found of these that worked well / cleanly! A++ 💡

  11. Knox July 2, 2008 at 11:19 pm #

    Glad you found it useful – thanks, Shaun.

  12. Sheila July 14, 2008 at 5:32 pm #

    iPhone detection by websites in Safari on the iPhone is denying us the REAL INTERNET!

    Apple promised me the REAL INTERNET in Safari on the iPhone. Websites are taking that away from us with these stupid sites that detect the iPhone and redirect away from what I’m trying to do online. It is EXCEEDINGLY AGGRAVATING. There needs to be some way to keep them from doing that.

    For example, if I want to go to Jirbo.com’s regular site on my iPhone in Safari, I should have that choice. The site should surface a dialog asking “iPhone or Regular Web?” But no, no go. Go to that site yourself in iPhone and try, I dare you, try to click the Contact link to get to the contact form. It redirects. And there’s no equivalent given for the iPhone.

    PLEASE, Apple, hear us, do something right away about this before it gets out of control! I’m at a cafe and I have to go HOME to browse a site because of this? Terrible!

  13. Knox July 15, 2008 at 6:09 pm #

    Sheila, that’s quite a rant. Actually, Jirbo CATERS to iPhoners – and I was actually solicited to work for them. Your issues seam to be yours.

    Apple is not injecting redirection scripts into other websites, WEBSITE OWNERS are. Apple isn’t ruining anything. If a site owner is directing you to a site catered to iPhones they do it because that’s the experience THEY WANT TO PROVIDE.

    If you want “the real internet” – mobile Safari is the truest rendering out there, hands down. The site owners can decide to detect the user-agent ad direct according to their wishes regardless of what Apple desires, or you.

  14. david July 16, 2008 at 7:36 pm #

    you can also use a service like handsetdetection.com which will identify most phones, pdas and blackberrys. It also does some cool location based stuff.

  15. Granata August 11, 2008 at 8:23 am #

    Over the weekend I was trying to decide if the iPhone detection feature is something I should use for a site that I am working on. I can see the point Sheila is trying to make but ultimately I concluded that the “real” browsing experience will never be 100% transferable to the iPhone. Here’s why:

    1. The screen is just too small. Something like Knox’s template makes presenting information much easier and faster than zooming and panning all over the place and clicking on tiny text links and buttons.

    2. The context is not the same. The only browsing I do on my mobile is for quick information and bulleted details If I want the full story I’ll wait to get to my desktop. This not only applies to how I present data but also to what data I choose to present on the mobile site.

    It can be frustrating when a website locks you out of it’s classic view and I think it’s bad form. However, I see nothing wrong with designing specifically for a particular platform.

  16. mikbarrett October 13, 2008 at 10:51 pm #

    Sheila was completely on point here. If the website in question offers quality, up-to-date content in the ‘iphone mobile” version that it redirects you to, that’s one thing. But there are already sites I’ve noticed that are way ahead of themselves. They’ve gone all ga-ga about redirecting iphone users to their “mobile” sites, without considering the fact that the mobile version of their site is absolute crap, compared to the real thing.

    In addition, I resent the notion that everyone out there needs to be placated with some quick and painless, watered down version of the internet. As Sheila said, maybe I don’t want some poor man’s idea of the original website. Maybe I’m familiar with how the real website looks, I know where things are on that site that I’m interested in, and I’m willing to wait a few extra freaking seconds for it to load on my GD iphone, so I thereby want the freaking CHOICE of going to the real website or a mobile one!

    ESPN.com has clued into this, giving people the option. Why can’t everyone else?! The whole thing makes me very angry.

  17. Knox October 13, 2008 at 11:03 pm #

    @mikbarrett Too funny. You came here by searching:

    “mobile websites are irritating iphone”

    – so you’re obviously biased and looking for a place to vent.

    Site owners can do what they want, present their content their way to who they want. This includes you. You also notice that THIS site doesn’t do what is so irritating to you – though a third of my traffic is for iPhone specific webapps. Maybe I’ll add it, but I’d offer the choice. If this was a flash driven site then I would definitely use the script and you should be glad site owners do.

  18. ig88 December 23, 2008 at 10:37 am #

    i am a designer, and this script does work and redirects to my iphone, but what bit of code to add to it to load my normal site on a computer. seems like there needs to be an “else” statement in there.

    any help?

  19. ig88 December 23, 2008 at 10:41 am #

    ahh, think i got it. i will put it in the main index, rather than having a redirect page.

  20. Knox December 23, 2008 at 5:09 pm #

    @ig88 – exactly

  21. OutaTowner January 1, 2009 at 12:12 pm #

    I understand your opinion that we should be happy that a mobile user site was created in the first place. But I think that we the “customer” so to speak should be the ones who get to choose. And if you don’t understand that, then you have the poorest sense of what a good business needs. Because if iphone and itouch users get frustrated with your site, they will stop using it.

    So automatically redirect the site if you want, but please please give us the option the option to view the full site or at least an explanation why the site builder believes that it can’t be viewed

  22. doc30 January 21, 2009 at 8:08 am #

    I have to agree with the Iphone users here. Redirecting away from real websites is more than an irritation. I paid a premium for my iPhone specifically to look at the content of regular websites. Safari was designed to do that. The watered down websites are information poor and force you to navigate through a maze of menu trees and you are lucky if you find what you are looking for. There should be a way for user of iPhones and iPod Touchs to block website redirects, or to choose the mobile version if the real website is, for example, Flash heavy. For example, my local newspaper just did this and their classifieed ads are not accessible using the mobile version they just set up. Kind of dumb since advertising pays their bills and they are blocking it.

  23. lebsays June 19, 2009 at 11:26 am #

    as an iPhone user, I can say with confidently that there is no such thing- as an iPhone friendly website, and in fact- mobile websites rob iPhone users of features we love to use, and makes it more difficult to access information.

    I would ask, nay- beg! any developer; if you feel you must use a mobile version of a site, please leave an option to return to the full version!

    Personaly, I would rather never see a mobile site ever again, but maybe that’s just me.

Leave a Reply