Detect IPhone, IPad or IPod User With 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.

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.

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


Leave a reply