Detecting screen resolution then redirecting

They have: 2 posts

Joined: Jul 2000

I'm a newbie to javascripting and need some help, please.

I want to add a script to a site I'm designing that will detect a client's screen resolution and then redirect them to the appropiate page set for their resolution. Can someone point me to a site that has an of this script or post a script I can use?

I've done some searching, but have only seen examples of telling a client what his/her resolution is and nothing else.

Thanks

They have: 231 posts

Joined: Feb 2000

var userWidth = screen.width;
var userHeight = screen.height;

if (userWidth == 640 && userHeight == 480) {
location = "page640480.html";
}
else if (userWidth == 800 && userHeight == 600) {
location = "page800600.html";
}

:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::

They have: 2 posts

Joined: Jul 2000

Quote: Originally posted by Lloyd Hassell
var userWidth = screen.width;
var userHeight = screen.height;

if (userWidth == 640 && userHeight == 480) {
location = "page640480.html";
}
else if (userWidth == 800 && userHeight == 600) {
location = "page800600.html";
}

It worked like a charm - thanks!

Is it possible to incorporate a setTimeout function? I want the redirect to the appropiate page to be delayed by about 10 seconds.

They have: 231 posts

Joined: Feb 2000

Easy:

if (userWidth == 640 && userHeight == 480) {
window.setTimeout("location = 'page640480.html'",1000 * 10);
}

They have: 99 posts

Joined: May 1999

Probably goes without saying, but be carefull on the conditionals....

Have a fall back redirect so that if the user has say 1600x1280 that you have a match on your conditional statements.

I recommend using a set such as:

var userWidth = screen.width;
var userHeight = screen.height;

if (userWidth <= 640){
myWidth=640;
}else if (userWidth <=800){
myWidth=800;
}else{
myWidth=1024;
}
if (userHeight <= 480) {
userHeight =480;
}else if (userHeight <=600){
userHeight =600;
}else{
userHeight =768;
}

if(myWidth>=1024 && myHeight>=768){
location = "page1024768.html";
} else if (myWidth >= 800 && myHeight >= 600) {
location = "page800600.html";
} else {
location = "page640480.html";
}

This is a verbose example, you can certainly combine the two sections, key is to make sure you cover odd sizes/combos.

Tazman

[Edited by tazman on 07-15-2000 at 03:34 PM]

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.