var width;
            var height;
            //获取窗口宽度
            if (window.innerWidth)
                width = window.innerWidth;
            else if ((document.body) && (document.body.clientWidth))
                width = document.body.clientWidth;
            //获取窗口高度
            if (window.innerHeight)
                height = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                height = document.body.clientHeight;
原文:http://www.cnblogs.com/change4now/p/5665143.html