Skip to content

Instantly share code, notes, and snippets.

@tkadlec
Created July 15, 2012 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkadlec/3118128 to your computer and use it in GitHub Desktop.
Save tkadlec/3118128 to your computer and use it in GitHub Desktop.
Device Pixel Ratio Test
//Adapted from http://www.broken-links.com/2012/07/13/using-media-queries-to-test-device-resolution
var dpr = window.devicePixelRatio,
msg = '';
// devicePixelRatio property
if (dpr) { msg += 'devicePixelRatio: ' + dpr; }
// matchMedia method
if (window.matchMedia) {
// resolution feature & dpi unit
if (window.matchMedia('(min-resolution: 96dpi)').matches) { msg += '\ndpi: true'; }
// resolution feature & dppx unit
if (window.matchMedia('(min-resolution: 1dppx)').matches) { msg += '\ndppx: true'; }
// -webkit-device-pixel-ratio feature
if (window.matchMedia('(-webkit-min-device-pixel-ratio: 1)').matches) { msg += '\n-wk-dpr: true'; }
// -o-device-pixel-ratio feature
if (window.matchMedia('(-o-min-device-pixel-ratio: 1/1)').matches) { msg += '\n-o-dpr: true'; }
// min--moz-device-pixel-ratio feature
if (window.matchMedia('(min--moz-device-pixel-ratio: 1)').matches) { msg += '\n-moz-dpr: true'; }
}
window.alert(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment