Search code examples
javascriptretina-display

Does devicePixelRatio change when the browser window is dragged between monitors?


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.


Solution

  • 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