obtaining client resolution

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

obtaining client resolution

Post by davidklonski »

Hi

I am trying to fit my page content based on the client resolution.
Is it possbile to retrieve that information in PHP? and if so how?

thanks in advance
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

this is not server-side...

your thinking of a javascipt

Code: Select all

<SCRIPT LANGUAGE="Javascript">
if (screen.width < 800 && screen.height < 600) &#123;
     document.write("Site best viewed with a 800 by 600 resolution.");
&#125;
else &#123;
     document.write("Your current resolution is bigger than 800 by 600.");
&#125;
</SCRIPT>
Hope this helps
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

Post by davidklonski »

What can I do if I want to render content (in the server-side) based on the client resolution? For example, I if the resolution is high enough, I would like to display some content from the database. If the resolution is not high enough, don't display anything.

If I am at the client side, than it is too late and the page at already been rendered.

Isn't there a way to do it in PHP?

thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

No there isn't a way to directly grab the resolution via PHP you have to use client-side scripting like Javascript.

Mac
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

You could simply build both possible pages with php and then let javascript decide between them
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

use javascript to do stylesheet switching. in the low-res version of the stylesheet, have those database entried styled with display: none;
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

of course, you'd better make it sure it degrades properly if javascript is turned off.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

yea true make low-res the default
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Why not give the user a choice? They may have a high resolution but browse with the window quite small or they may have a low resolution but not mind scrolling sideways...

Mac
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Make an entry screen. Whether a login screen, or a quick redirect, have the entry screen detect their browser size.

Then, using http redirect, send them to the next page, with a variable set with the browser size.

Simple, effective, and gives PHP the knowledge of the client-side.

Ideally, if it can't detect it, it should default to low resolution.

Of course, the best idea would be to avoid locked-resolution designs at all costs. Consider people that need to increase their font sizes for accessibility, people that use palm devices, and so on..

If you design the site to be accessible, you wont need locked-resolutions. The obvious sidenote being that locked-resolutions are almost never accessible.
Post Reply