窗口大小

2017-06-16 15:19:00
admin
原创
557
<!DOCTYPE html>
<html>
<head>
    <title>Window Size Example</title>
</head>
<body>
    <p>Hello world!</p>
    <script type="text/javascript">

        var pageWidth = window.innerWidth,
            pageHeight = window.innerHeight;
            
        if (typeof pageWidth != "number"){
            if (document.compatMode == "CSS1Compat"){
                pageWidth = document.documentElement.clientWidth;
                pageHeight = document.documentElement.clientHeight;
            } else {
                pageWidth = document.body.clientWidth;
                pageHeight = document.body.clientHeight;
            }
        }

        alert("Width: " + pageWidth);
        alert("Height: " + pageHeight);
    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络