【发布时间】:2011-10-30 17:33:32
【问题描述】:
<html>
<body REMonload="document.location.assign('index2.php?w=' + window.innerWidth + '&h=' + window.innerHeight);">
<script language="javascript">
document.write('w=' + window.innerWidth + '&h=' + window.innerHeight);
</script>
</body>
</html>
输出:
w=981&h=425
为什么?维基百科说,w 应该是 960。
问候,
更新
我发现,问题与 viewport 元标记有关。
下面的代码做了我想看到的:
<html style="width:100%; height:100%;">
<head>
<meta name="viewport" content="width=device-width; initial-scale=0.5; minimum-scale=0.5; maximum-scale=0.5; user-scalable=no;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
</head>
<body style="width:100%; height:100%; background-color: blue;"
REMonload="document.location.assign('index2.php?w=' + window.innerWidth + '&h=' + window.innerHeight);"
onload="alert('w=' + window.innerWidth + '&h=' + window.innerHeight);">
</body>
</html>
看看这个元数据:
name="viewport" content="width=device-width; initial-scale=0.5; minimum-scale=0.5; maximum-scale=0.5; user-scalable=no;"
我不明白,它是如何工作的。我已经尝试过设备宽度的系数 1.0(我想是 960),但似乎我需要的是 0.5。
无论如何,它适用于我的 iPod Touch 4 (960*640)。
您能否在 iPad 或 iPad2 和 iPhone/iPod Touch 1 或 2 或 3 上尝试该代码?是对应的1024/768和480/320吗?换句话说,我可以对任何 Apple 设备使用相同的解决方案吗?
提前致谢!
【问题讨论】:
标签: web-applications width iphone-4