获取移动设备的宽和高,onload获取的值和用户刷新页面的获取的值不一致
页面代码如下:
<!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>
页面加载之后显示的值与加载之后用户刷新页面获取的值不一样?
主要是页面高不一致,为什么呢?