redirect visitors based on both screen resolution and browser

Discussion in 'Javascript' started by one.1more, Feb 26, 2007.

  1. one.1more

    one.1more Guest

    I have the following code but its not working. i want my site to be
    accessible only if the visitors resolution is 1024 x 768 or higher and
    only if they are using internet explorer. the version is not important
    because i think most people have 5.5+
    When i visit my my site with 800 x600 either by using firefox or IE,
    it redirects me to useie.htm. but if i use firefox with 1024 x 768, it
    doesnt redirect me to useie.htm. why? can someone fix my code?

    <script language="javascript" type="text/javascript">
    browserName = navigator.appName;
    if ((screen.width<=1024) && (screen.height<=768)&& (browserName!
    ="Microsoft Internet Explorer"))

    (i also tried putting var in front of browserName when its first
    declared, it didnt work that way either)
    one.1more, Feb 26, 2007
    1. Advertisements

  2. one.1more

    Darko Guest

    Just simple use of logic in your if-expression. If you want to allow
    only users that use both ie AND 1024x768, then you need to redirect
    all the users that either don't have ie OR don't have 1024x768 or
    higher. So the correct expression would be:
    if ( (screen.width<1024 && screen.height<768) || (browserName !=
    "Microsoft Internet Explorer") )
    // redirect...

    The easier way for you, if you're not aware of logical expressions
    rules, would be the following: first write the expression that
    recognizes users you want to ALLOW, and then negate the whole
    if ( ! ((screen.width>=1024 && screen.height>=768) && (browserName ==
    "Microsoft Internet Explorer")) )
    // redirect...
    Darko, Feb 26, 2007
    1. Advertisements

  3. one.1more

    one.1more Guest

    it works. thank you
    one.1more, Feb 27, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.