FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Programming question -- detecting screen resolution.

   
Author Topic: Programming question -- detecting screen resolution.
El JT de Spang
Member
Member # 7742

 - posted      Profile for El JT de Spang   Email El JT de Spang         Edit/Delete Post 
I wrote my music site in php (not that I needed to; just to see if I could), and I'm noticing that it displays poorly in IE6 and older and in resolutions above 1024x768.

The main page of the site is centered around a large background image, and all the text and menu stuff is on top of it. I'd like to detect the user's screen resolution and, if it's larger than 1024x768, display a larger background image.

Is there a simple way to do this? I've seen some javascript code that supposedly does this, but I don't know squat about js.

Posts: 5462 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
The only simple ways are using javascript.

Give whatever element you are setting the background image on (presumably using CSS) an id and a class. Set all but the image properties in a selector using the id, and all the image properties in a selector using the class. Also have another class in your CSS that has the larger image properties. (You can forego the id if you set the properties on a unique element, such as body, though it could still be helpful for the javascript).

Perhaps the id is 'content', the original class is 'small', and the new class is 'large'.

Put the following javascript (inside a script tag) into your page. It should be okay in the document head somewhere.

code:
if(screen.width > 1000) {
document.getElementById('content').className = 'large';
}

Warning, untested, post here if that doesn't work.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
If you are planning to do anything more complicated, you can get the resolution into php by reading it in javascript, writing a cookie, and then reading the cookie in php. This is a pretty standard way of passing informstion between them.
Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
El JT de Spang
Member
Member # 7742

 - posted      Profile for El JT de Spang   Email El JT de Spang         Edit/Delete Post 
Thanks, I'll try that. It won't be today, though, cause I don't have ftp access right now.

I'm bookmarking this thread.

Posts: 5462 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
NotMe
Member
Member # 10470

 - posted      Profile for NotMe   Email NotMe         Edit/Delete Post 
Be careful how large you scale things. If you stretch the body text wider than 1024, you will probably end up with lines that are too long to be readable. Use the extra horizontal space for columns of things like navigation links.

There's also nothing wrong with just not stretching things horizontally, either. Even though my screen is 1680 pixels wide, I almost never have my browser taking up more than two-thirds of the width, because most sites will stretch text across 17".

Posts: 145 | Registered: Apr 2007  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
The cookie method would be inferior to ajax or json (edit: via dynamic script tags) in this case, likely (and in most cases).
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2