首页 > 代码库 > 每天一个JavaScript实例-确定web页面的区域

每天一个JavaScript实例-确定web页面的区域

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-确定web页面的区域</title>
<script>
function size(){
	var width = 0;
	var height = 0;
	if(!window.innerWidth){
		width = (document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body.clientWidth);
		height = (document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body.clientHeight);
	}else{
		width = window.innerWidth;
		height = window.innerHeight;
	}
	return {width:width,height:height};
}
window.onload = function(){
	var viewPort = size();
	var w = viewPort.width;
	var h = viewPort.height;
	console.log(w);
	console.log(h);
}
</script>
</head>

<body>

<div id = "date">
</div>

</body>
</html>

每天一个JavaScript实例-确定web页面的区域