3

I am trying to obtain the screen scaling on the client machine - the value in the image below. As you can see it's set to 150%.

I've tried window.devicePixelRatio, which returns 1.5 - which is what I want, but only if the browser zoom is at 100%. I am unclear how to get zoom level in a modern browser, which precludes me from getting accurate screen scaling.

Am I missing a simple way to obtain screen scaling?

enter image description here

P.S. This question doesn't solve anything because the ratio as the same as zoom, which makes it impossible to find the scaling. See example.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • Possible duplicate of [How to detect page zoom level in all modern browsers?](https://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers) – Raymond Nijland May 07 '19 at 22:53
  • @RaymondNijland That code doesn't work. Zoom Level is the same as Ratio, which makes it impossible to find scaling. You can check it yourself. http://tombigel.github.io/detect-zoom/ – AngryHacker May 07 '19 at 23:16
  • Try this: https://stackoverflow.com/questions/4130649/detect-browser-zoom-level-using-javascript – shadow2020 May 07 '19 at 23:20
  • My guess is that, because this is a user setting, you cannot and should not have any knowledge of it because it's none of your business what the user wants to do with their viewing of the browser. If you were able to view the value, then you could adjust your content to display something different than what the user wants but what the user wants, again, is none of your business. – Rob May 07 '19 at 23:22
  • @Rob I am serving images. The 600px wide image seems washed out and fuzzy on a screen with 200% screen scaling. I'd like to serve a 1200px wide for those screens to make it seem sharper. – AngryHacker May 07 '19 at 23:24
  • @shadoe2020 That code may have worked once upon a time (circa 2010). It is accurate anymore. – AngryHacker May 07 '19 at 23:28
  • It's working for me – shadow2020 May 07 '19 at 23:30
  • @shadoe2020 This snippet `parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width,10)/document.documentElement.clientWidth` returns either 1 or 0.9994086339444116 depending on the zoom level. What are you seeing? I tried it in Firefox and Chrome. – AngryHacker May 07 '19 at 23:33
  • Ok try one more then I give up. This should work, it's also working for me. `https://stackoverflow.com/a/54770411/11059320` – shadow2020 May 07 '19 at 23:35
  • Maybe you should check and try out the html 5 picture tag? – Raymond Nijland May 07 '19 at 23:37
  • I can't behind my firewall – shadow2020 May 07 '19 at 23:37

0 Answers0