jQuery Detect Mobile Devices – iPhone iPod iPad

Sam Deering
Share

jQuery code snippet to detect if a user is viewing the website using a mobile device, specifically an iPhone iPod or iPad. You may also wish to detect the mobile browser type.

jQuery(document).ready(function($){
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {

        // mobile code here
 
	}
});