For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > April 2005 > Screen resolution









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Screen resolution
Wouter

2005-04-18, 3:56 pm

How can I determine the screen resolution of the user who is viewing my
website?
I want to use this do show a different background image and to hide some
elements when the resolution is less than 1024 * 768.

Wouter



Oli Filth

2005-04-18, 3:56 pm

Wouter wrote:
> How can I determine the screen resolution of the user who is viewing my
> website?
> I want to use this do show a different background image and to hide some
> elements when the resolution is less than 1024 * 768.
>


I assume you mean browser window size? Which is unrelated to screen
resolution. Not with PHP directly.

You can probably do it with Javascript (unreliably) and then send the
values back in a new request.


--
Oli
coolsti

2005-04-19, 8:55 am

On Mon, 18 Apr 2005 19:33:20 +0200, Wouter wrote:

> How can I determine the screen resolution of the user who is viewing my
> website?
> I want to use this do show a different background image and to hide some
> elements when the resolution is less than 1024 * 768.
>
> Wouter


You can do this with Javascript, but then you need to worry about whether
the user has Javascript enabled, and then the whole cross browser issue
(different browsers may use different commands and variables to get the
screen width).

With IE, I get the screen width only when my user logs on to my
application (I assume the screen width won't change during a session) with

document.form1.screenwidth.value = screen.width;

where here I have a form named form1, and a hidden variable named
screenwidth. On the server side I get the screenwidth from the $_POST
array and save it in the session array after the user successfully logs in:

$_SESSION['screenwidth'] = trim($_POST['screenwidth'])

and then I use this on whatever pages need to be dependent on the screen
width. Of course you need to check that the value is reasonable, as
not all browsers will understand what you use to determine screen width,
and you need to handle cases where the user disables javascript. In my
case, all my navigation is performed using Javascript. If javascript is
disabled, my audience doesn't get anywhere anyway.

Oli Filth

2005-04-20, 8:56 pm

Wouter wrote:
> How can I determine the screen resolution of the user who is viewing my
> website?
> I want to use this do show a different background image and to hide some
> elements when the resolution is less than 1024 * 768.
>


I assume you mean browser window size? Which is unrelated to screen
resolution. Not with PHP directly.

You can probably do it with Javascript (unreliably) and then send the
values back in a new request.


--
Oli
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com