
当窗口调整大小时,会触发resize事件。在JavaScript中使用 window.outerWidth和window.outerHeight事件来获取浏览器调整大小时的窗口大小。
示例
你可以尝试运行以下代码来使用JavaScript中的onresize事件。
<!DOCTYPE html>
<html>
<head>
<script>
function resizeFunction() {
var val = "Window Width=" + window.outerWidth + ", Window Height=" + window.outerHeight;
document.getElementById("test").innerHTML = val;
}
</script>
</head>
<body onresize="resizeFunction()">
<p>Resize browser window and check the window (browser window) height and width again.</p>
<p id = "test"> </p>
</body>
</html>

