获取移动设备的宽和高,onload获取的值和用户刷新页面的获取的值不一致

sizhiguo 2011-06-24 04:23:18
页面代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META name=viewport content=width=device-width,minimum-scale=1.0,maximum-scale=1.0>
<script>
function alertSize()
{
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
document.write( "Width = " + myWidth );
document.write( "Height = " + myHeight );
}
</script>
<body onload="a()">

</body>
<script type="text/javascript">
function a()
{
alertSize();
}
</script>
</html>

页面加载之后显示的值与加载之后用户刷新页面获取的值不一样?
主要是页面高不一致,为什么呢?
...全文
75 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sizhiguo 2011-06-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xuexiaodong2009 的回复:]

window.innerWidth
document.documentElement.clientWidth
document.body.clientWidth

是相同的东西吗?
[/Quote]
浏览器不同,有些浏览器不支持
xuexiaodong2009 2011-06-24
  • 打赏
  • 举报
回复
window.innerWidth
document.documentElement.clientWidth
document.body.clientWidth

是相同的东西吗?

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧