我需要使用 php 获取页面高度的代码,请任何人帮助我。
谢谢
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.
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);
}
});
我认为是这样的:
<?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'];
?>
这可行,但非常难看,我希望你真的不需要这个。