2

I know browser-detection is supposed to be taboo, but I'm out of ideas.

I have a website that I want to be nice and full-featured when running on a full-sized computer and simple to use when on an iPhone (or other smart phone). What's the right thing to do here?

Malvolio
  • 38,966
  • 24
  • 87
  • 125

3 Answers3

12

you can do it with simple javascript

function isiPhone(){
    return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1)
    );
}
if(isiPhone()){
   alert('iPhone detected');
}
Senad Meškin
  • 12,841
  • 4
  • 37
  • 53
2

Are you using JQuery? Sure you are! Who isn't, right? Put this in a file called jquery.browser.mobile.js and then reference it.

(function (a) {
jQuery.browser.iDevice = /ip(hone|od|ad)/i.test(a);
})(navigator.userAgent || navigator.vendor || window.opera);

This will allow you to check for specific instances that you are on an Apple product.

if ($.browser.iDevice) {
    // do something exciting
}

The reason you'd want to do something like this, is because Apple products fire touch events and not click events. So you might want to hook up handlers to elements differently on Apple products.

Khalid Abuhakmeh
  • 10,383
  • 10
  • 48
  • 75
1

Well.. I don't completely understand the question, so I will answer what I understood.

To find the browsers that are iPhone, you will use the javascript in the page to get the navigator.userAgent . The useragent has unique info to iPhone. You can look through it and find it out that way. To see how the iphone useragent differs from a PC user agent, go to whatsmyuseragent.com from both, and you will see the different useragents.

frosty
  • 16,905
  • 5
  • 43
  • 70