<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document</title>
<script type="text/javascript">
<!--
window.onload=function(){
var w=document.documentElement.clientWidth,//也可以以scrollWidth,scrollWidth包括滚动条
h=document.documentElement.clientHeight;
var d=document.getElementById("popup");
var ow=d.offsetWidth,
oh=d.offsetHeight;
alert(oh);
d.style.left=(w-ow)/2+"px";
d.style.top=(h-oh)/2+"px";
}
//-->
</script>
</head>
<body>
<!--一定要设置position:absolute否则不能-->
<div id="popup" style="position:absolute;400px;height:400px;border:1px solid gray;">
我是猪
</div>
</body>
</html>