You can listen to the media query with matchMedia , which will tell you when devicePixelRatio will pass a certain barrier (unfortunately, not for arbitrary scale changes).
eg:
window.matchMedia('screen and (min-resolution: 2dppx)'). addListener(function(e) { if (e.matches) { } else { } });
The listener will be called when you drag the window between monitors, as well as when connecting or disconnecting an external monitor without a retina (if it forces the window to move from the retina to the screen without the retina or vice versa).
window.matchMedia supported in IE10 + and all other modern browsers .
Links: https://code.google.com/p/chromium/issues/detail?id=123694 , MDN at min-resolution
source share