Detect IPhone, IPad or IPod User With Javascript

Updated: in Javascript

With mobile devices becoming more and more popular there will be times when you need to do something different for users coming to your site from one of these mobile devices.

If you want to change the design depending on the mobile device you will use media queries. But if you want to change functionality such as Javascript then you can use the below snippet to do something different for mobile devices.

<script>
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
	alert('You are using an iPhone, ipod or an ipad');
}
</script>

I've added this script to this page so if you visit this page on a iPhone, ipod or an ipad then you will see an alert box.

Keep updated with the latest tutorials and snippets.

Join me on Twitter | G+ | Facebook

Learn Web Design, Coding & More. No Risk. No Contracts. Learn More