js获取浏览器宽度和高度值
生活随笔
收集整理的這篇文章主要介紹了
js获取浏览器宽度和高度值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>請調整瀏覽器窗口</title> <meta http-equiv="content-type" content="text/html>
</meta></head>
<body>
<h2 align="center">請調整瀏覽器窗口大小</h2><hr />
<form action="#" method="get" name="form1" id="form1">
<!--顯示瀏覽器窗口的實際尺寸-->
瀏覽器窗口 的 實際高度: <input type="text" name="availHeight" size="4"/><br />
瀏覽器窗口 的 實際寬度: <input type="text" name="availWidth" size="4"/><br />
</form>
<script type="text/javascript">
<!--
var winWidth = 0;
var winHeight = 0;
function findDimensions() //函數:獲取尺寸
{
//獲取窗口寬度
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) && (document.body.clientWidth))
winWidth = document.body.clientWidth;
//獲取窗口高度
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
//通過深入Document內部對body進行檢測,獲取窗口大小
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
//結果輸出至兩個文本框
document.form1.availHeight.value= winHeight;
document.form1.availWidth.value= winWidth;
}
findDimensions();
//調用函數,獲取數值
window.οnresize=findDimensions;
//-->
</script>
</body>
</html>
轉載于:https://www.cnblogs.com/ince/p/10520815.html
總結
以上是生活随笔為你收集整理的js获取浏览器宽度和高度值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis-sentinel 主从复制高
- 下一篇: 安振平老师的4911号不等式问题的证明