月关宝盒
你不能用纯PHP来做这件事。您必须用JavaScript来完成它。有几篇关于如何做到这一点的文章。本质上,您可以设置cookie,甚至可以执行Ajax将信息发送到PHP脚本。如果使用jQuery,可以这样做:jQuery:$(function() {
$.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
if(json.outcome == 'success') {
// do something with the knowledge possibly?
} else {
alert('Unable to let PHP know what the screen resolution is!');
}
},'json');});PHP(Somescript.php)<?php// For instance, you can do something like this:if(isset($_POST['width']) && isset($_POST['height'])) {
$_SESSION['screen_width'] = $_POST['width'];
$_SESSION['screen_height'] = $_POST['height'];
echo json_encode(array('outcome'=>'success'));} else {
echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));}?>所有这些都是基本的,但它应该会让你有所收获。通常情况下,屏幕分辨率并不是你真正想要的。您可能更感兴趣的是实际浏览器的视图端口的大小,因为这实际上是页面呈现的地方.