zoukankan      html  css  js  c++  java
  • JavaScript获取屏幕和页面的宽度和高度

    JavaScript获取屏幕和页面的宽度和高度


    1、设计源码

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>宽度和高度</title>
    <script type="text/javascript">
        function widthAndHeight()
    	{
    		//网页可见区域宽
    		var clientWidth = document.body.clientWidth;
    		//网页可见区域高
    		var clientHeight = document.body.clientHeight;
    		//网页正文全文宽
    		var scrollWidth = document.body.scrollWidth;
    		//网页正文全文高
    		var scrollHeight = document.body.scrollHeight;
    		//网页可见区域宽(包括边线的宽)
    		var offWidth = document.body.offsetWidth;
    		//网页可见区域高(包括边线的宽)
    		var offHeight = document.body.offsetHeight;
    		//屏幕分辨率的宽
    		var screenWidth = window.screen.width;
    		//屏幕分辨率的高
    		var screenHeight = window.screen.height;
    		//屏幕可用工作区宽度
    		var avaWidth = window.screen.availWidth;
    		//屏幕可用工作区高度
    		var avaHeight = window.screen.availHeight;
    		
    		document.writeln("网页可见区域宽:" + clientWidth + "<br>");
    		document.writeln("网页可见区域高:" + clientHeight + "<br>");
    		document.writeln("网页正文全文宽:" + scrollWidth + "<br>");
    		document.writeln("网页正文全文高:" + scrollHeight + "<br>");
    		document.writeln("网页可见区域宽(包括边线的宽):" + offWidth + "<br>");
    		document.writeln("网页可见区域高(包括边线的宽):" + offHeight + "<br>");
    		document.writeln("屏幕分辨率的宽:" + screenWidth + "<br>");
    		document.writeln("屏幕分辨率的高:" + screenHeight + "<br>");
    		document.writeln("屏幕可用工作区宽度:" + avaWidth + "<br>");
    		document.writeln("屏幕可用工作区高度:" + avaHeight + "<br>");
    		
    	}
    </script>
    </head>
    
    <body>
       <input type="button" id="btn" value="宽度和高度" οnclick="widthAndHeight()"/>
    </body>
    </html>
    

    2、运行结果

    (1)初始化

           

    (2)点击后

    网页可见区域宽:1309
    网页可见区域高:26
    网页正文全文宽:1325
    网页正文全文高:577
    网页可见区域宽(包括边线的宽):1309
    网页可见区域高(包括边线的宽):26
    屏幕分辨率的宽:1366
    屏幕分辨率的高:768
    屏幕可用工作区宽度:1366
    屏幕可用工作区高度:728


  • 相关阅读:
    动软代码生成器 修改配置
    显示转换explicit和隐式转换implicit
    Memcache学习整理
    SQL2008-分页显示3种方法
    SQL2008-表对表直接复制数据
    SQL2008-删除时间字段重复的方法
    SQL2008-中不想插入从复记录
    SQL2008-c:PROGRA~1COMMON~1SystemOLEDB~1oledb32.dll出错找不到指定的模块
    ACCESS-如何多数据库查询(跨库查询)
    ACCESS-字符函数
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315289.html
Copyright © 2011-2022 走看看