redirect visitors based on both screen resolution and browser

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

  1. Guest

    Hello,
    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?
    Code:

    <script language="javascript" type="text/javascript">
    <!--
    browserName = navigator.appName;
    if ((screen.width<=1024) && (screen.height<=768)&& (browserName!
    ="Microsoft Internet Explorer"))
    {
    window.location="http://mysite.com/useie.htm;
    }
    //-->
    </script>

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

  2. Darko Guest

    On Feb 26, 2:00 pm, wrote:
    > Hello,
    > 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?
    > Code:
    >
    > <script language="javascript" type="text/javascript">
    > <!--
    > browserName = navigator.appName;
    > if ((screen.width<=1024) && (screen.height<=768)&& (browserName!
    > ="Microsoft Internet Explorer"))
    > {
    > window.location="http://mysite.com/useie.htm;}
    >
    > //-->
    > </script>
    >
    > (i also tried putting var in front of browserName when its first
    > declared, it didnt work that way either)


    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
    expression:
    if ( ! ((screen.width>=1024 && screen.height>=768) && (browserName ==
    "Microsoft Internet Explorer")) )
    // redirect...
    Cheers
     
    Darko, Feb 26, 2007
    #2
    1. Advertising

  3. Guest

    On Feb 26, 12:02 pm, "Darko" <> wrote:
    > On Feb 26, 2:00 pm, wrote:
    >
    >
    >
    > > Hello,
    > > 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?
    > > Code:

    >
    > > <script language="javascript" type="text/javascript">
    > > <!--
    > > browserName = navigator.appName;
    > > if ((screen.width<=1024) && (screen.height<=768)&& (browserName!
    > > ="Microsoft Internet Explorer"))
    > > {
    > > window.location="http://mysite.com/useie.htm;}

    >
    > > //-->
    > > </script>

    >
    > > (i also tried putting var in front of browserName when its first
    > > declared, it didnt work that way either)

    >
    > 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
    > expression:
    > if ( ! ((screen.width>=1024 && screen.height>=768) && (browserName ==
    > "Microsoft Internet Explorer")) )
    > // redirect...
    > Cheers


    it works. thank you
     
    , Feb 27, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Evans

    Redirect visitors to registration page

    Paul Evans, Dec 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    356
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Dec 21, 2004
  2. Pat
    Replies:
    5
    Views:
    547
  3. meltedown
    Replies:
    9
    Views:
    1,036
    Steve Pugh
    Oct 17, 2006
  4. Brent
    Replies:
    8
    Views:
    202
    Thomas 'PointedEars' Lahn
    May 10, 2004
  5. Replies:
    2
    Views:
    74
    Stephen Chalmers
    Oct 6, 2005
Loading...

Share This Page