JQuery – Target platforms with jQuery

Much as we might want to execute certain CSS for certain devices, we might also want to run jQuery only on specific devices.
Here is an adaptation of some code from Snipplr that allows me to easily segment portions of jQuery to run depending on the user’s device.

 var deviceAgent = navigator.userAgent.toLowerCase();
 var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
 if(agentID.indexOf("iphone")>=0){
  alert("iphone");
 }
 if(agentID.indexOf("ipod")>=0){
  alert("ipod");
 }
 if(agentID.indexOf("ipad")>=0){
  alert("ipad");
 }
 if(agentID.indexOf("android")>=0){
  alert("android");
 }

Leave a Reply

Your email address will not be published. Required fields are marked *

*