javascript - 为什么 javascript 报告 Motorola Atrix MB860 4G 的宽度为 800px?不应该是540px吗

标签 javascript android web-applications motorola screen-size

对于我的移动 Web 应用程序,我试图让设备的屏幕宽度动态适应 View 。

我真的很困惑为什么摩托罗拉 Atrix Atrix MB860 报告 800px 宽度。当我看到这个设备的规范时,它的分辨率是 540x960。为什么在 javascript 中它报告 800px?我使用了这个测试页: http://www.quirksmode.org/m/tests/widthtest.html screenshot from motorola atrix

我在几个设备上测试了上面的页面,除了摩托罗拉 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/

相关文章:

algorithm - Web 服务器上分配的内存增长

go - 是否有任何自动增量机制用于使用 redigo 包装器将键值存储在 redis 中?

javascript - Cordova/PhoneGap Android 应用程序中的 Maxlength 和复制粘贴

android - 在 Android Studio 中使用 Graph API 从 JSON 对象中检索数据

java - Android - 如何根据 if else 语句的返回值设置界面颜色

javascript - 在 Web 应用程序中动态加载 'pages' 或屏幕的最佳方法

javascript - 如何使用 lodash 使用另一个具有 bool 值的数组对数组进行子集化

javascript - 如何在没有拼接的情况下更新数组(angularjs)元素?

javascript - 在 AWS Lambda 中模拟

android 应用停止运行