/** * Returns string of detected phone basic type * if its an iPhone, iPod or android (phone resoulution) * * @return (truthy) string or false */ function litterAppDetectedPhone() { // Because we only want to serve the app to phones // and NOT TO TABLETS for Android we need to check the // screen width height this varies but this script checks sizes // based on this info from: http://stackoverflow.com/a/19955647/738957 // 800 x 480 (62%) // 480 x 320 (14%) // 960 x 540 (6%) // 480 x 854 (5%) // 320 x 240 (5%) // Therefor we check if width is no greater than 540 // and height is no greater than 960 // UPDATE: client requested 720 x 1280 // so its going to turn up on a lot of tablets now anyway var maxAndroidPhoneHeight = 1280, maxAndroidPhoneWidth = 720; var device = false; if(navigator.userAgent.match(/iPhone/i)) device = 'iPhone'; if(navigator.userAgent.match(/iPod/i)) device = 'iPod'; if(navigator.userAgent.toLowerCase().indexOf('android') > -1) { if(screen.width <= maxAndroidPhoneWidth && screen.height <= maxAndroidPhoneHeight) { device = 'android'; } } return device; } (function($){ $(function(){ if(litterAppDetectedPhone()) { $('.app-target-device').show(); $('.not-app-target-device').hide(); }else{ $('.app-target-device').hide(); $('.not-app-target-device').show(); } }); }(jQuery));