Here’s a simple JS function to return the type of device based on screen size and some other helpful variables for the main manufacturers.
// mobile check function checkForMobile() { var x = screen.width; var y = screen.height; var agent = navigator.userAgent.toLowerCase(); var mobileOS = typeof orientation != 'undefined' ? true : false; var touchOS = ('ontouchstart' in document.documentElement) ? true : false; var otherBrowser = (agent.indexOf("series60") != -1) || (agent.indexOf("symbian") != -1) || (agent.indexOf("windows ce") != -1) || (agent.indexOf("blackberry") != -1); var iOS = (navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPad") != -1) ? true : false; var android = (agent.indexOf("android") != -1) || (!iOS && !otherBrowser && touchOS && mobileOS) ? true : false; var istablet = (/ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase())); var tablet = (istablet==true && x >= 768) ? true : false; // is it mobile if(x >= 320) { whichDevice = "Mobile"; } if(tablet==true) { whichDevice = "Tablet"; } if(x >= 800 && tablet==false) { whichDevice = "Desktop"; } return whichDevice; } //sets the device type checkForMobile();
Found something better? , please let me know.