By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 2,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

redirect visitors based on both screen resolution and browser

P: n/a
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 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Feb 26, 2:00 pm, one.1m...@gmail.com 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

Feb 26 '07 #2

P: n/a
On Feb 26, 12:02 pm, "Darko" <darko.maksimo...@gmail.comwrote:
On Feb 26, 2:00 pm, one.1m...@gmail.com 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 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.