繁体   English   中英

使用PHP获取浏览器窗口大小/分辨率

[英]Get browser window size/resolution with PHP

我有一个以导航栏开头的页面,具有特定的高度,在此之下我放置了一个代码,该代码应该填充其余的高度。 我怎么能为各种分辨率编码呢? 我需要浏览器的“工作区”大小。

这就是我做到的。 我刚用这个简单的小工具替换了我的index.php,并重命名了我的index.php index2.php。 它只是使用纯javascript检查这些东西,并将它们作为$ _GET变量传递给您的真实索引文件。 还有什么比这更容易? 全部完成! 花了我5分钟,你需要30秒:)

<html>
<head>
    <script type="text/javascript">

        if(window.innerHeight > window.innerWidth){
            var landscapeOrPortrait = 'portrait';
        } else {
            var landscapeOrPortrait = 'landscape';
        }

        var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

        var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;



        window.location.replace('index2.php?width='+width+'&height='+height+'&landscapeOrPortrait='+landscapeOrPortrait);            
    </script>            
</head>

$window_width = "<script type='text/javascript'>document.write(window.innerWidth);</script>";

无法用PHP完成。 即使可以, 这个CSS也是一个更好的解决方案。

您遇到了最烦人的CSS问题。 这个问题似乎有很多答案,因为有人问它。 上面的链接是我在这个问题上找到的最好,最跨浏览器友好的解决方案。

不要让关于页脚的部分让你感到困惑。 如果你不想要一个页脚,它仍然可以完美地工作。

使用绝对定位。

.nav {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100px;
}
.content {
    position: absolute;
    top: 100px;
    left: 0;
    right: 0;
    bottom: 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM