zoukankan      html  css  js  c++  java
  • 网页宽度高度获取方法备忘

    function gets()
    {
    var s ="网页可见区域宽:"+ document.body.clientWidth;
    s += "<br>网页可见区域高:" + document.body.clientHeight;
    s += "<br>网页可见区域宽:" + document.body.offsetWidth +" (包括边线的宽)";
    s += "<br>网页可见区域高:" + document.body.offsetHeight +" (包括边线的宽)";
    s += "<br>网页正文全文宽:" + document.body.scrollWidth;
    s += "<br>网页正文全文高:" + document.body.scrollHeight;
    s += "<br>网页被卷去的高:" + document.body.scrollTop;
    s += "<br>网页被卷去的左:" + document.body.scrollLeft;
    s += "<br>网页正文部分上:" + window.screenTop;
    s += "<br>网页正文部分左:" + window.screenLeft;
    s += "<br>屏幕分辨率的宽:" + window.screen.width;
    s += "<br>屏幕分辨率的高:" + window.screen.height;
    s += "<br>屏幕可用工作区宽度:" + window.screen.availWidth;
    s += "<br>屏幕可用工作区高度:" + window.screen.availHeight;
    document.getElementById('dd').innerHTML = s;
    }

    你可以参考下面这个函数,这个函数是获取完整页面尺寸的函数(即你说的浏览器能看到的区域,不包括被滚动条卷去的区域)
    -----------------------------js代码---------------------------------------------------------
    <script>
    function GetPageSize(){
        var xScroll, yScroll;
        if (window.innerHeight  &&  window.scrollMaxY) { 
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) {
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement  &&  document.documentElement.clientHeight) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        } 
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else { 
            pageHeight = yScroll;
        }
        if(xScroll < windowWidth){ 
            pageWidth = windowWidth;
        } else {
            pageWidth = xScroll;
        }
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
        return arrayPageSize;
    }
    alert(GetPageSize());
    </script>
    
  • 相关阅读:
    [转]让IIS支持FLEX的MXML格式
    将图片上传到数据库 因File.Open遭遇System.UnauthorizedAccessException
    WinForm Control 命名规范
    生成随机但又有规律可循的一组问答数 以提供远程授权服务
    [转]winform 安装部署
    silverlight相关
    [转]对WinForm的App.config文件进行加密
    [转]项目经理是这样当的
    CSS
    SQLServer下 存储过程内 包含事务 及 返回处理是否成功
  • 原文地址:https://www.cnblogs.com/nanfei/p/3282553.html
Copyright © 2011-2022 走看看