JavaScript

Javascript: Detect iPhone, iPod, iPad

Have ever ever thought of display custom information to the user or making changes in the browser depending upon whether the user is using iPhone, iPod or iPad? Here is a snippet in Javascript: Detect iPhone, iPod, iPad using this handy snippet!

How to Detect iPhone, iPod, iPad using JavaScript – Examples

Insert the following snippet just above your </head> tag:

<script type="text/javascript">
//Make your JS compatible by using the following tags
//<![CDATA[

// Apple detection object
var Apple = {};
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d++) {
var t = Apple.Types[d];
Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));
Apple.Device = Apple.Device || Apple[t];
}
// is this an Apple device?
/*alert(
"Apple device? " + Apple.Device +
"\niPhone? " + Apple.iPhone +
"\niPod? " + Apple.iPod +
"\niPad? " + Apple.iPad
);*/
if ( true == Apple.iPhone )
{
 //do this
}
else  if ( true == Apple.iPod )
{
//do this
}
else  if ( true == Apple.iPad )
{
//do this
}

//]]>
</script>
That’s it!

Did you like this post? Do you know of any other ways to detect iPhone, iPod, iPad using JavaScript? Feel free to suggest by commenting below. We would love to hear from you.

4 Comments on Javascript: Detect iPhone, iPod, iPad

  1. 1

    I used to be recommended this website by way of my cousin.
    I am now not certain whether this publish is written via him as no one else recognize such designated approximately my difficulty.
    You’re wonderful! Thanks!

  2. 2

    This really answered my problem, thanks!

  3. 4

    Wow, amazing blog structure! How lengthy have you been running a blog for? you make running a blog glance easy. The overall look of your site is excellent, let alone the content material!

Leave a Reply to Robert Cancel reply

*

*