What is the best way to detect retina support on a device using JavaScript?

后端 未结 4 742
时光取名叫无心
时光取名叫无心 2020-11-28 04:58

Right now I am using this function:

function is_retina_device() {
    return window.devicePixelRatio > 1;
}

But its simplicity scares me

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 05:26

    devicePixelRatio is not reliable at all. when you zoom in to 200%, the window.devicePixelRatio will return you 2, but you are not on a retina display.

提交回复
热议问题