Monitor Resolution Detection for Tables

fsn812 0 Tallied Votes 478 Views Share

A very simple PHP/Javascript snippet to detect the resolution of a user's monitor and create a table using that resolution to best fit within the user's browser (to avoid scrolling). Note: This is a PHP script which includes Javascript

<?php
$url = $_SERVER['PHP_SELF'];

if(isset($HTTP_COOKIE_VARS["res"]))
$res = $HTTP_COOKIE_VARS["res"];

else{
?>
<script language="javascript">
<!--
go();

function go() 
{
 var today = new Date();
 var the_date = new Date("August 31, 2020");
 var the_cookie_date = the_date.toGMTString();
 var the_cookie = "res="+ screen.width +"x"+ screen.height;
 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
 document.cookie=the_cookie
 location = '<?echo "$url";?>';
}
//-->
</script>
<?php
}
?>
<?php
//Let's "split" the resolution results into two variables
list($width, $height) = split('[x]', $res);

//Take the width and height minus 300
$tb_width = $width-300;
$tb_height = $height-300;

//Make the table
print("<table align=center border=1 width=" .$tb_width . " height=" . $tb_height . " >
<tr><td align=center>Your screen resolution is " . $width . " by " . $height . ".<br>
The width/height of this table is " . $tb_width . " by " . $tb_height . ".</td></tr>
</table>");
?>
Lapin 0 Newbie Poster

Assuming it is a bug-free script, I think it is very good. It makes it possible to create completely resolution-flexible websites, including font and image sizes that vary with the resolution.

Thanks!

Aber 0 Newbie Poster

Thank you,

That is very good and helpful

Best Regards,
Ali Cholmaghani

almostbob 866 Retired: passive income ROCKS

the date of the original post is 2005
and no-body has heard of % or em, in this conversation at that point in time
it is unncessary to know the size of the window to write scaleable code

W3C recommendations for browser/screen/window independent code??

tables are inefficient outdated for most purposes??

css positioning??

current best practice can be picked up at http://www.w3schools.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.