How to execute javaScript function only when using IPhone / iPad

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

Something like that:

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

      

How to do it?

Thank!

+3


source to share


2 answers


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

      



+3


source


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



+2


source







All Articles