I am using window.devicePixelRatio which works on Andriod and Iphone but does not work in IE 10 Windows mobile. any alternative?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- Keeping track of variable instances
For a IE fallback, both desktop and mobile, use:
Actually, none of the previous answers are correct. All tests below were made on Lumia 520 phones having an LCD screen of 480*800:
WP8/IE Mobile 10:
Expected devicePixelRatio is 480/320 = 1.5 which can be calculated by:
(The rounding is needed to get a valid LCD screen size)
WP8.1/IE Mobile 11:
Expected devicePixelRatio is (once again) 480/320 = 1.5 which can be calculated by:
So even if window.devicePixelRatio is present it will give you the ratio between DOM screen size and LCD screen size, however, the DOM screen size is larger than the available viewport size. If you want to know the exact ratio between CSS pixels and device pixels, then you have to make the calculations above. Also, these calculations are valid in portrait mode. In landscape mode use screen.availHeight instead (DOM screen dimensions do not change on orientation change on IE Mobile).
I found that on a Nokia Lumia 1230 the property window.devicePixelRatio returns 1 even if the value is clearly incorrect. Testing for window.screen.deviceXDPI / window.screen.logicalXDPI returns 1.52083333. So using window.devicePixelRatio first is not a good idea.
I would suggest the following:
For some reason, using the best way to test for the presence of the deviceXDPI in the screen object:
does not work on this phone.
Got it from http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/08/internet-explorer-10-brings-html5-to-windows-phone-8-in-a-big-way.aspx