<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获得网页内容的有效长度和宽度</title>
</head>
<script type="text/javascript">
function get_page_size()
{
var re = {};
if (document.documentElement && document.documentElement.clientHeight)
{
//针对IE以外的浏览器
var doc = document.documentElement;
re.width = (doc.clientWidth>doc.scrollWidth)?doc.clientWidth-1:doc.scrollWidth;
re.height = (doc.clientHeight>doc.scrollHeight)?doc.clientHeight:doc.scrollHeight;
document.write(re.width+"</br>");
document.write(re.height+"</br>");
}
else
{
//针对IE浏览器
var doc = document.body;
re.width = (window.innerWidth>doc.scrollWidth)?window.innerWidth:doc.scrollWidth;
re.height = (window.innerHeight>doc.scrollHeight)?window.innerHeight:doc.scrollHeight;
document.write(re.width+"</br>");
document.write(re.height+"</br>");
}
return re;
}
</script>
<body>
<input type="button" οnclick="get_page_size()" value="click"/>
</body>
</html>