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.
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!
computer repair rockville
March 10, 2012 at 8:57 pm
This really answered my problem, thanks!
April 3, 2012 at 11:58 pm
Glad to be of help.
Robert
April 4, 2012 at 4:43 pm
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!
Krista
April 14, 2012 at 6:49 pm