Just Holden Commodores - Free Advertising - Debt Consolidation - Debt Consolidation - Debt Consolidation

PDA

View Full Version : detect screen size and redirect


letitia
Feb 19th 2007, 1:07 pm
I am new to this forum so sorry if this has already beeen covered but I couldn't find anything that helped when I searched.
I am know actionscript but not js. I am building a site in flash where there are 2 different versions of the site for large and small screen sizes and I am using the following javascript to detect the screen resolution and then show the approprate site. But it won't work! I have never needed to ask anything before but this really has me stumped, any help at all would be appreciated and I would offer any help that I can provide with actionscript in return. sorry for being so dumb...

<script type="text/javascript">
// <![CDATA[
var w = screen.width;
var h = screen.height;

if(w == 800 && h == 600){
location = 'home_small.html';
}else if(w == 1024 && h == 768){
location = 'home_small.html';
}else if(w == 1280 && h == 1024){
location = 'home.html';
}else if(w == 1600 && h == 1200){
location = 'home.html';
}
</script>

I also tried using greater and smaller than so that I dont need to list each screen size individually, but no luck...
:)

nico_swd
Feb 19th 2007, 1:13 pm
http://www.quirksmode.org/viewport/compatibility.html

letitia
Feb 19th 2007, 1:18 pm
will give this a read, thankyou!
do i have the redirect bit ok then with the 'location'...?

nico_swd
Feb 19th 2007, 1:20 pm
Oh, try:

window.location = 'home_small.html';

instead. :)

EDIT:

You should also have an else (No else if), incase there's no match, so the user will be redirected to a default page.

letitia
Feb 19th 2007, 1:24 pm
ahh that might help, its tricky when you keep changing bits and you don't know when you've got something right or not because another bit is wrong. I really appreciate the help, thankyou!

letitia
Feb 20th 2007, 9:37 am
still working on this but for others who may be having a similar problem this page looks like it could (hopefully) yield some answers

http://molly.com/articles/markupandcss/1999-09-route.php

when i have something working i will try and post up the code