-2

我需要使用 php 获取页面高度的代码,请任何人帮助我。

谢谢

4

3 回答 3

2

PHP is a server side scripting language and a browser page is a client-side resource. You are mixing two different things. There is no direct way to get page height or width using PHP. However, if you can use JavaScript to set a cookie with page height and read the same cookie from PHP, you might achieve what you are looking for.

于 2013-10-09T04:51:28.857 回答
1

There is no method to get page height in php

You could do in js as,

var ww = $( window ).height(); // returns height of browser viewport
var ww = $( document ).height(); // returns height of HTML document,

You can pass this to your php file by AJAX

$.ajax({
    url: 'phpfile.php',
    type: 'POST',
    data: { data : ww },
    success: function (result) {
        doSomethingWithResult(result);
    }
});
于 2013-10-09T04:53:40.500 回答
0

我认为是这样的:

<?php
 if(!$_REQUEST['pageHeight']){
   echo "
     <script src="jquery url here"/>
     <script>
       function getPageHeight(){
         return (window).height();//or some other way
       }
       $(document).ready(function(){
         var url = location.href.split('?'); 
         location.href = 
                url[0]+'?'+(url[1]?url[1]+'&':'')+'pageHeight='+getPageHeight();
       })
     </script>";
     return;
  }
  echo $_REQUEST['pageHeight'];
?>

这可行,但非常难看,我希望你真的不需要这个。

于 2013-10-09T05:03:17.597 回答