[JS語法] 自動抓取瀏覽器高度

自動抓取瀏覽器高度

HTML 

<!DOCTYPE html>
<html>
<head>
<script src="AutoHight.js"></script>
<title>自動高度</title>
</head>

<body onresize="AutoSetHeight()">
    <span id='BrowserHeight'>瀏覽器高度</span><br/>
</body>

</html>

 AutoHight.js

function AutoSetHeight() {
    var WinHeight = window.innerHeight;
    var tag = document.getElementById('BrowserHeight')
    var body = document.getElementsByTagName('body')[0];

    tag.innerText = WinHeight;
    body.style.height = WinHeight + "px";
}