5

With a retina Macbook Pro, it's possible to plug in an external monitor and you drag a browser window between the retina screen and the other, normal-DPI display.

Does this cause window.devicePixelRatio to dynamically change? And if so, is there any event I can monitor for when this happens?

I don't have one in front of me to test. I need to know because I might need to re-draw a canvas if it changes.

callum
  • 34,206
  • 35
  • 106
  • 163

1 Answers1

4

Yes the devicePixelRatio changes, and you can detect it with matchMedia.

I think that you should have a look at this topic that give a more detailled answer for detect the change:

https://stackoverflow.com/a/29653772/3914736

Community
  • 1
  • 1
Allan Raquin
  • 583
  • 7
  • 26
  • 1
    Note that if you set `devicePixelRatio` with JavaScript (e.g. open your console and type `devicePixelRatio = 1`) it appears to be fixed to that value and does not change to match the new display. – ericsoco Dec 11 '17 at 22:17
  • @ericsoco To you know how to re-set it to a dynamic value, so that it gets updated again? – Annenarg Jan 10 '22 at 14:11