最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

jquery - How to execute a javaScript function only when using an IPhoneIPad - Stack Overflow

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far