首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

js获取页面宽高及浏览器宽高

Posted on 2013-04-02 14:14  达奇  阅读(260)  评论(0编辑  收藏  举报
     //返回页面的高度
        function pageHeight() {
            if (window.innerHeight && window.scrollMaxY) { yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { yScroll = document.body.scrollHeight; } else { yScroll = document.body.offsetHeight; }
            return yScroll;
        }

        //返回页面的宽度
        function pageWidth() {
            if (window.innerWidth && window.scrollMaxX) { xScroll = window.innerWidth + window.scrollMaxX; } else if (document.body.scrollWidth > document.body.offsetWidth) { xScroll = document.body.scrollWidth; } else { xScroll = document.body.offsetWidth; }
            return xScroll;
        }

        //返回浏览器的高度
        function windowHeight() {
            return (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
        }

        //返回浏览器的宽度
        function windowWidth() {
            return (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
        }