Monitor Resolution Detection for Tables

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
fsn812 fsn812 is offline Offline Oct 24th, 2005, 5:37 am |
0
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
Quick reply to this message  
JavaScript / DHTML / AJAX Syntax
  1. <?php
  2. $url = $_SERVER['PHP_SELF'];
  3.  
  4. if(isset($HTTP_COOKIE_VARS["res"]))
  5. $res = $HTTP_COOKIE_VARS["res"];
  6.  
  7. else{
  8. ?>
  9. <script language="javascript">
  10. <!--
  11. go();
  12.  
  13. function go()
  14. {
  15. var today = new Date();
  16. var the_date = new Date("August 31, 2020");
  17. var the_cookie_date = the_date.toGMTString();
  18. var the_cookie = "res="+ screen.width +"x"+ screen.height;
  19. var the_cookie = the_cookie + ";expires=" + the_cookie_date;
  20. document.cookie=the_cookie
  21. location = '<?echo "$url";?>';
  22. }
  23. //-->
  24. </script>
  25. <?php
  26. }
  27. ?>
  28. <?php
  29. //Let's "split" the resolution results into two variables
  30. list($width, $height) = split('[x]', $res);
  31.  
  32. //Take the width and height minus 300
  33. $tb_width = $width-300;
  34. $tb_height = $height-300;
  35.  
  36. //Make the table
  37. print("<table align=center border=1 width=" .$tb_width . " height=" . $tb_height . " >
  38. <tr><td align=center>Your screen resolution is " . $width . " by " . $height . ".<br>
  39. The width/height of this table is " . $tb_width . " by " . $tb_height . ".</td></tr>
  40. </table>");
  41. ?>
0
Lapin Lapin is offline Offline | Nov 23rd, 2007
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!
 
 

Message:


Similar Threads
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC