redirect visitors based on both screen resolution and browser

O

one.1more

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)
 
D

Darko

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
 
O

one.1more

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top