admin管理员组

文章数量:1023221

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!

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!

Share Improve this question edited Apr 11, 2013 at 15:39 James Cazzetta asked Apr 2, 2012 at 11:18 James CazzettaJames Cazzetta 3,2206 gold badges36 silver badges55 bronze badges 1
  • 3 possible duplicate of Detect iPad users using jQuery? – Felix Kling Commented Apr 2, 2012 at 11:19
Add a ment  | 

2 Answers 2

Reset to default 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();
}

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

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!

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!

Share Improve this question edited Apr 11, 2013 at 15:39 James Cazzetta asked Apr 2, 2012 at 11:18 James CazzettaJames Cazzetta 3,2206 gold badges36 silver badges55 bronze badges 1
  • 3 possible duplicate of Detect iPad users using jQuery? – Felix Kling Commented Apr 2, 2012 at 11:19
Add a ment  | 

2 Answers 2

Reset to default 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();
}

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

本文标签: jqueryHow to execute a javaScript function only when using an IPhoneIPadStack Overflow