JavaScript中的innerWidth 属性返回宽度,innerHeight属性返回窗口内容区域的高度。语法: window.innerWidth
window.innerHeight 参数:它不需要任何参数。 返回值:返回一个数字,表示窗口内容区域的宽度和高度。 注意:对于IE 8 ie(Internet Edg 8)或更早版本,请使用clientWidth和clientHeight获取窗口的宽度和高度。 示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浏览器内部的宽度和高度</title>
<style>
body{
text-align:center;
}
.gfg {
font-size:40px;
font-weight:bold;
color:green;
}
</style>
</head>
<body>
<div class = "gfg">PHP中文网</div>
<h2>浏览器窗口</h2>
<p id="demo"></p>
<script>
var Width, Height, result;
// 浏览器窗口的高度和宽度
Width = window.innerWidth || document.documentElement.clientWidth
|| document.body.clientWidth;
Height = window.innerHeight || document.documentElement.clientHeight
|| document.body.clientHeight;
// 显示宽度和高度。
result = document.getElementById("demo");
result.innerHTML = "浏览器内部宽度: " + Width +
"<br>浏览器内部高度: " + Height;
</script>
</body>
</html> 输出: 
相关推荐:《javascript教程》 本篇文章就是关于JavaScript中Window innerWidth和innerHeight属性的相关介绍,希望对需要的朋友有所帮助! 以上就是JavaScript中innerWidth和innerHeight属性详解的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |