window.screen.width and window.screen.height -- should they adjust to the windows Scaling value or not? |
||||
Issue descriptionI am on Windows Chrome 71.0.3578.98. My Windows 10 scaling is at 125%, because the Windows UI is otherwise too small on my screen. For browsers, this means I have to adjust scaling by the inverse (80%) to see websites as they were intended to be seen. This correctly reports a window.devicePixelRatio of 1. I am building a web-app, and one variable I am looking to get (for UI scaling purposes) is the maximum window size. In Edge and Firefox, window.screen.width, when the window.devicePixelRatio is 1, this value is 1920, which is my actual pixel screen size. In Chrome (given my 125% Windows scaling), the number is 1536, which is 1920 / 1.25. The way I have come up with to go around this issue is: var adj = (window.screen.width == window.outerWidth) ? 0 : -15 var maxScreenWidth = window.innerWidth * (window.screen.width / (window.outerWidth + adj)) if (parseInt(maxScreenWidth) != maxScreenWidth) maxScreenWidth = window.screen.width This horrible code seems to work for Chrome, Edge, and Firefox. Still, I would like to ask if the "1536" report on window.screen.width is actually a bug. Shouldn't it really be 1920?
,
Jan 20
(2 days ago)
,
Jan 21
(2 days ago)
,
Jan 21
(2 days ago)
There are good arguments both ways but it would be good if there was some consistency across browsers obviously. Changing it is likely to break existing content though which is a bit of a concern.
,
Yesterday
(46 hours ago)
I did spend quite some time searching for a solution on StackOverflow, and found a partial (but currently incorrect) solution for getting zoom here: https://stackoverflow.com/a/16867412/1136569 It was using an adjustment value of 16... now it is 15... So a couple things on the pro-change side -- 1) Getting the zoom value is already known to be a mess per the original post at https://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers/6365777, at least for older browsers. And in any case, it isn't something a lot of people are trying, according to the number of upvotes (or maybe they're not finding the question). 2) What are they doing with the zoom value? Probably not getting the maximum window width like me.... (???) So maybe a smaller impact than might be otherwise anticipated. 3) As you see in my solution, it is possible to not have to do a user agent detection to get the value. 4) My solution does have at least one weakness: that -15 adjustment value could change at any time, as it already did, I think. Still it should be not a huge deal in that case. Cons: 1) The change can randomly break a (small [possibly 0 though]) amount of websites. 2) Even though this standardizes with Firefox and Edge, Edge's engine will share Chrome's in the future, leaving just Firefox as the odd man out... (Still, I think Firefox is probably doing it the "right" way.) |
||||
►
Sign in to add a comment |
||||
Comment 1 by agamem...@gmail.com
, Jan 20 (3 days ago)