Skip to content

Instantly share code, notes, and snippets.

@davidji99
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save davidji99/9140803 to your computer and use it in GitHub Desktop.

Select an option

Save davidji99/9140803 to your computer and use it in GitHub Desktop.
/*
The below function was derived from https://github.com/davidji99/isMobile
Please visit the link above for further instructions if needed.
*/
//paste the follow code into the Satisfy this custom JS condition field in Targeting
(function(i){var e=/iPhone/i,n=/iPod/i,o=/iPad/i,t=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,r=/Android/i,d=/BlackBerry/i,s=/Opera Mini/i,a=/IEMobile/i,b=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,h=RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),c=function(i,e){return i.test(e)},l=function(i){var l=i||navigator.userAgent;this.apple={phone:c(e,l),ipod:c(n,l),tablet:c(o,l),device:c(e,l)||c(n,l)||c(o,l)},this.android={phone:c(t,l),tablet:!c(t,l)&&c(r,l),device:c(t,l)||c(r,l)},this.other={blackberry:c(d,l),opera:c(s,l),windows:c(a,l),firefox:c(b,l),device:c(d,l)||c(s,l)||c(a,l)||c(b,l)},this.seven_inch=c(h,l),this.any=this.apple.device||this.android.device||this.other.device||this.seven_inch},v=i.isMobile=new l;v.Class=l})(window);
screen.width < 1280 || isMobile.any
//end copy
/*
Explanation:
- screen.width looks at the device's resolution. You can change this to another condition if needed
- isMobile.any targets any mobile device whether it's an Android, Apple, Windows, etc. You can change this setting as well
following the guidelines set forth in https://github.com/davidji99/isMobile
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment