[support] Different theme based on screen resolution?

Seth Freach sfreach at gmail.com
Sat Nov 8 16:36:33 UTC 2008


The fundamental problem is that the theme selection must be done at PHP 
runtime on the web server, while any JavaScript used to determine 
resolution (or view port size) will run well after this stage at the 
client.  With a strait forward approach of PHP running on the server to 
deliver a webpage, there is no way for the PHP to know the screen 
resolution at runtime. 

But, it is possible if you take a two stage approach, I don't know of 
any theme that actually does this though (but that's not to say that 
there aren't any).

Stage 1 is the initial page request.  The PHP runs and serves JS to the 
client.  When that JS runs, it can determine the screen resolution and 
use the values for the request of the second stage.

Stage 2 is the JS requesting that same page again, but with the 
resolution values as part of the request.

A snippet could roughly look like this:

<?php
if ($_GET['screenx'] && $_GET['screeny']) {

 // $_GET['screenx'] and $_GET['screeny'] are our resolution values
 // make any decisions you want based on them, theme selection, etc..

}
else {
  |// this assumes HTTP, adapt as needed.  Use request_uri() to work on 
non apache servers too|
  |$url = 'http://' . ||$_SERVER['SERVER_NAME'] . ||request_uri()||; |
  print <<<ENDJS
  <script>
    location.href = $page + '&screenx=' + screen.width + '&screeny=' + 
screen.height;
  </script>
ENDJS;
  exit;
}
?>

Keep in mind though that if you are turning each request into two 
requests you could run into performance issues.  Better to store the 
resolution values in $user['session'].


-Seth

Florent JOUSSEAUME wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The resolution depends on your browser's size. You can be with a
> resolution of  1280x1024 but your browser with a size of 800x600.
>
>  bharani kumar a écrit :
>   
>> Sorry if i understood wrongly,
>>
>> Actually question is different theme based on resolution , not an size
>>
>> Thanks
>>
>>
>>
>>
>>
>> On Sat, Nov 8, 2008 at 1:37 PM, sivaji j.g <sivaji2009 at gmail.com
>> <mailto:sivaji2009 at gmail.com>> wrote:
>>
>>
>>
>>         to display a different theme based on a users
>>         screen resolution?
>>
>>
>>     I think you can do this with java script
>>
>>     <script type="text/javascript">
>>     function alertId()
>>     {
>>     alert(screen.width);
>>     alert(screen.height);
>>     }
>>     </script>
>>
>>     Now you know the resolution of user, just call the required
>>     theme. Module is not required for this .
>>
>>     
>>     --
>>     Thanks a lot
>>     -----------------------------------------
>>     http://ubuntuslave.blogspot.com/
>>
>>
>>     --
>>     [ Drupal support list | http://lists.drupal.org/ ]
>>
>>
>>
>>
>> --
>> உங்கள் நண்பன்
>> பரணி  குமார்
>>
>> Regards
>> B.S.Bharanikumar
>>
>> POST YOUR OPINION
>> http://bharanikumariyer.hyperphp.com/
>>     
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkkVkBMACgkQ3nayFuuvNJOyTACggBt8lZGqx/FPPbiHkpd8kRZW
> UN4AoJJeXPJ+vpszBL58BRr5DFnFdVkZ
> =xate
> -----END PGP SIGNATURE-----
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20081108/9af19d4f/attachment.htm 


More information about the support mailing list