zoukankan      html  css  js  c++  java
  • js监控窗口高度和宽度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>请调整浏览器窗口</title>
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    </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.onresize=findDimensions;
    //-->
    </script>
    </body>
    </html>

  • 相关阅读:
    Redis操作命令大全
    Redis实用监控工具一览
    Redis缓存雪崩、缓存穿透、缓存击穿、缓存降级、缓存预热、缓存更新
    Redis GEO地理位置信息,查看附近的人
    详解redis持久化
    详解Supervisor进程守护监控
    详解Redis Cluster集群
    arduino使用rfid
    树莓派控制WS2812
    Arduino读取温湿度dh11+烟雾气体MQ2+彩灯ws2812
  • 原文地址:https://www.cnblogs.com/huangf714/p/5922585.html
Copyright © 2011-2022 走看看