对于我的移动 Web 应用程序,我试图让设备的屏幕宽度动态适应 View 。
我真的很困惑为什么摩托罗拉 Atrix Atrix MB860 报告 800px 宽度。当我看到这个设备的规范时,它的分辨率是 540x960。为什么在 javascript 中它报告 800px?我使用了这个测试页: http://www.quirksmode.org/m/tests/widthtest.html
我在几个设备上测试了上面的页面,除了摩托罗拉 atrix 之外,它们都正确地报告了宽度。例如 galaxy s2 报告 480px 和 nexus 7 报告 1280px
最佳答案
这是 Android 2.3 的一个奇怪行为。我在这里发现的:http://tripleodeon.com/2011/12/first-understand-your-screen
Android v2.3, in a regular browser scenario, however, displays even more curious behavior. Its screen.width always starts off as 800 – which is clearly some sort of virtual viewport, rather than the physical screen. But when the document has an XHTML-MP doctype, or a constrained viewport (for any doctype), the value will switch, by the time of the document load event, to be the 320 or 480 you might expect.
window.outerWidth 应该可以解决问题或将视口(viewport)宽度设置为设备宽度
<meta name="viewport" content="width=device-width, user-scalable=no" />
关于javascript - 为什么 javascript 报告 Motorola Atrix MB860 4G 的宽度为 800px?不应该是540px吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14368384/