User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 363,784 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,539 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Oct 24th, 2005
Views: 6,476
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
javascript Syntax | 2 stars
  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. ?>
Comments (Newest First)
Lapin | Newbie Poster | 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!
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 10:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC