JavaScript中的innerWidth
属性返回宽度,innerHeight属性返回窗口内容区域的高度。
语法:
1 2 | window.innerWidth
window.innerHeight
|
Salin selepas log masuk
参数:它不需要任何参数。
返回值:返回一个数字,表示窗口内容区域的宽度和高度。
注意:对于IE 8 ie(Internet Edg 8)或更早版本,请使用clientWidth和clientHeight获取窗口的宽度和高度。
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <!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>
|
Salin selepas log masuk
输出:

相关推荐:《javascript教程》
本篇文章就是关于JavaScript中Window innerWidth和innerHeight属性的相关介绍,希望对需要的朋友有所帮助!
Atas ialah kandungan terperinci JavaScript中innerWidth和innerHeight属性详解. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!