• 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


  • 相关阅读:
    hadoop中namenode发生故障的处理方法
    开启虚拟机所报的错误:VMware Workstation cannot connect to the virtual machine. Make sure you have rights to run the program, access all directories the program uses, and access all directories for temporary fil
    Hbase的安装与部署(集群版)
    分别用反射、编程接口的方式创建DataFrame
    用Mapreduce求共同好友
    SparkSteaming中直连与receiver两种方式的区别
    privot函数使用
    Ajax无刷新显示
    使用ScriptManager服务器控件前后台数据交互
    数据库知识
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315289.html
Copyright © 2020-2023  润新知