window.screen.width / height不应该与实际的屏幕宽度/高度相对应吗? [英] Shouldn't window.screen.width/height correspond to actual screen width/height?

查看:1658
本文介绍了window.screen.width / height不应该与实际的屏幕宽度/高度相对应吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的Kindle 3G中使用WebKit浏览器,我注意到 window.screen.width window.screen.height 不反映实际的屏幕尺寸。物理屏幕(或更确切地说,纸张)尺寸 800 x 600 。我得到:

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 横向模式

  • 600 x 706 处于纵向模式

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

但有趣的是,Chrome和Safari(也是WebKit)都在运行我的桌面会报告实际的屏幕分辨率。

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

根据 MDC ,这些属性不是任何规范的一部分,因此可能没有严格定义宽度/高度应报告的内容。但是,不应该预期它们会反映实际的屏幕尺寸吗?

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?

推荐答案

更新:

我们在使用window.screen.width的模拟器中看到的问题是当我们使用不反映设备实际像素的屏幕时。所以你在屏幕上看到的是320,设备有480或者其他什么。但是,我不明白为什么屏幕宽度的值会给屏幕上的模拟器大小而不是实际像素。

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对我不起作用。

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

这将返回视口的值。在我的情况下,我正在运行HTML5应用程序。显然,此值不会在缩放时更新。

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.

他们在Android的Webkit上存在一些与此尺寸有关的问题。您可以在此处查看来自Android的开发者在此处讨论。可能已在Honeycomb中修复。

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.

这篇关于window.screen.width / height不应该与实际的屏幕宽度/高度相对应吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆