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


Get browser window size/resolution with PHP

我有一个页面,它以一个导航栏开始,具有特定的高度,并在其下面放置了一个代码,该代码应该填充其余的高度。如何针对不同的分辨率进行编码?我需要的是浏览器的"工作区"大小

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

不能在PHP中完成。即使它可以,这个CSS是一个更好的解决方案。

你遇到了现存的最烦人的CSS问题。这个问题的答案似乎和问这个问题的人一样多。上面的链接是我找到的解决这个问题的最好的,最跨浏览器友好的解决方案。

不要让关于页脚的部分迷惑了你。如果你不想要页脚,它仍然可以很好地工作。

我是这样做的。我只是用这个简单的小工具替换了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>

使用绝对定位

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