Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created July 22, 2012 20:43
Show Gist options
  • Save madrobby/3161015 to your computer and use it in GitHub Desktop.
Save madrobby/3161015 to your computer and use it in GitHub Desktop.
Detect retina support. Tested on iOS, Android 2.x, Chrome for Android, Safari on MacBook Pro Retina, Firefox mobile (beta) for Android, Opera Mobile (Android)
function isRetina(){
return (('devicePixelRatio' in window && devicePixelRatio > 1) ||
('matchMedia' in window && matchMedia("(min-resolution:144dpi)").matches))
}
@madrobby
Copy link
Author

I have updated the gist and moved away from the moz-specific check and test for min-resolution:144dpi. This works on Firefox (beta) on the Nexus 7, where as all other approaches (moz--min-device-pixel-ratio and min-resoution:1.5dppx) didn't.

@noamtm
Copy link

noamtm commented Aug 29, 2012

Also works on Chrome on MacBook Pro Retina (where window.devicePixelRatio==2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment