3

I want to execute a javascript function, only if the user is using an IPad / IPhone.

Something like this:

var checkifipadoriphone = true; //or false
if(checkifipadoriphone){
    executesomefuntion();
}

How does one do this?

Thanks!

James Cazzetta
  • 3,122
  • 6
  • 32
  • 54
  • 3
    possible duplicate of [Detect iPad users using jQuery?](http://stackoverflow.com/questions/4617638/detect-ipad-users-using-jquery) – Felix Kling Apr 02 '12 at 11:19

2 Answers2

3
function isiPhone(){
    return (
        //Detect iPhone
    //var isiPad = navigator.userAgent.match(/iPad/i) != null;
        (navigator.platform.indexOf("iPhone") != -1) ||
        //Detect iPod
        (navigator.platform.indexOf("iPad") != -1)
    );
}

if(isiPhone()){
    executesomefuntion();
}
James Cazzetta
  • 3,122
  • 6
  • 32
  • 54
2

Check out this page to see if you can use it to extract the browser type from the navigator object.

bdparrish
  • 3,216
  • 3
  • 37
  • 58