detect screen size and redirect

Discussion in 'JavaScript' started by letitia, Feb 19, 2007.

  1. #1
    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...
    :)
     
    letitia, Feb 19, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. letitia

    letitia Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    will give this a read, thankyou!
    do i have the redirect bit ok then with the 'location'...?
     
    letitia, Feb 19, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    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.
     
    nico_swd, Feb 19, 2007 IP
  5. letitia

    letitia Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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 19, 2007 IP
  6. letitia

    letitia Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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
     
    letitia, Feb 20, 2007 IP