Shouldn't window.screen.width/height correspond to actual screen width/height?

廉价感情. 提交于 2019-11-30 08:46:32

问题


Toying around with the WebKit browser in the new Kindle 3G, I noticed that window.screen.width and window.screen.height don't reflect the actual screen dimensions. The physical screen (or rather, paper) dimensions are 800 x 600. I get:

  • 800 x 506 in landscape mode
  • 600 x 706 in portrait mode

But interestingly, both Chrome and Safari (which are also WebKit) running on my desktop report the actual screen resolution.

According to MDC, these properties are not part of any specification, so there's probably no strict definition of what width/height should report. But, shouldn't it be expected that they reflect the actual screen dimensions?


回答1:


Update:

The issue we see in the emulator with window.screen.width is when we use screens which don't reflect the actual pixels of the device. So what you see on the screen is 320 and what the device has is 480 or whatever. I don't understand, though, why the value of screen width would give the emulator size on the screen and not the actual pixels.

This thing might be the same issue with the devices? If their density is higher at some sizes... for whatever the reason this could translate to some wrong screen width size?

Anyway, read below for my solution.


screen.availWidth does not work for me on certain screen sizes on the emulator.

Only thing is working for me now is:

window.innerWidth
window.innerHeight

Which will return the value of the Viewport. In my case I'm running an HTML5 app. This values will not update on zoom, apparently.

They have some issues with this sizes on Android's Webkit. You can see the devs from Android talking about it here. Probably fixed in Honeycomb.

Somebody claims it takes some sizes as if the soft keyboard would be present.




回答2:


I think WebKit can do nothing if it's getting wrong values from system. Sure these values should be represented by screen.availWidth and screen.availHeight, but I think this is related to event.screenX and event.screenY for mouse (pointer) positions.




回答3:


It would seem that screen.availWidth and screen.width are both returning the availWidth all the time, on many mobile operating systems.

I was unable to find any documentation on this however I did tested Android 2.2 and got the screen size minus the top menu bar exactly no matter what a requested.




回答4:


The difference are because the size of the Android status bar and or the bottom bar.



来源:https://stackoverflow.com/questions/3702073/shouldnt-window-screen-width-height-correspond-to-actual-screen-width-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!