Created
July 15, 2012 18:47
-
-
Save tkadlec/3118128 to your computer and use it in GitHub Desktop.
Device Pixel Ratio Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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