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.
1 |
<br />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');}<br /> |
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’);}