Reputation: 31
Has anyone discovered a reliable method to determine the device pixel ratio for Windows Phone 7.5 (Mango).
It is based off of IE9. In Webkit based browsers we have window.devicePixelRatio or using window.matchMedia() with the appropriate media query.
In Windows Mobile I can determine pixel ratio by doing: screen.deviceXDPI / screen.logicalXDPI though this appears to only be reliable once the page has been fully rendered. Prior to that deviceXDPI reports the same as logicalXDPI
Has anyone found a solution?
Thanks for any help/suggestions
Upvotes: 3
Views: 1927
Reputation: 24627
Use (min/max-)resolution as the equivalent test in a media query:
@media (min-resolution: 1.5dppx), (min-resolution: 144dpi), (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2) {}
or through matchMedia:
if (window.matchMedia)
{
if (window.matchMedia('(resolution: 96dpi)').matches) { }
// resolution feature & dppx unit
if (window.matchMedia('(min-resolution: 1dppx)').matches) { }
// -webkit-device-pixel-ratio feature
if (window.matchMedia('(-webkit-min-device-pixel-ratio: 1)').matches) { }
// -o-device-pixel-ratio feature
if (window.matchMedia('(-o-min-device-pixel-ratio: 1/1)').matches) { }
}
References
Upvotes: 0