JS案例:显示当前窗口占据显示器的区域大小

来自CloudWiki
跳转至: 导航搜索
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>显示当前窗口占用显示器的区域</title>
</head>
<body bgcolor="#fef4d2" >
<br>
<center>
<h2>显示占用区域</h2>
<hr width=300>
<br>
<script type="text/javascript">
function GetWinSize() {
  if (navigator.userAgent.indexOf("MSIE") > 0) {
     var sSize = (document.body.clientWidth * document.body.clientHeight);
     return sSize;}
  else {                                                
     var sSize = (window.outerWidth * window.outerHeight);
     return sSize;}
  return;      
}
var percent = Math.round((GetWinSize()/(screen.width * screen.height)*100) * Math.pow(10, 0));
document.write("此窗口占用当前显示器大约 " + "<FONT COLOR=#CC0033>"+percent+"%</FONT>" + " 的区域。");
</script>
</body>
</HTML>