Alex Rivera | Logout

How to detect the screen DPI using JavaScript

Asked 2012-02-15T11:05:36.020
18

The only way I found till now, is getting the offsetWidth, offsetHeight of a test div element with height and width of one inch: http://www.infobyip.com/detectmonitordpi.php

Is there a way to detect the screen DPI via JavaScript instead?

Thanks,

Atara.

Edit
Report

1 Answer

25

In webkit you can detect if your user has a so called "high dpi screen" by simply retrieving the value from:

window.devicePixelRatio

Normal dpi screens will return 1. The iPhone 4 will return 2, but numbers like 1.8 or 2.12 are also possible.

answered 2012-02-27T13:44:33.310

Your Answer