How to detect the screen DPI using JavaScript

前端 未结 3 525
余生分开走
余生分开走 2020-12-03 07:54

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:

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 08:22

    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.

提交回复
热议问题