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
2 Answers
Reset to default 3function 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.