473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

redirect visitors based on both screen resolution and browser

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
2 2338
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Larry Woods | last post by:
I am losing Session variables, but only those that are set in the page previous to a redirect to a secure page. Anyone seen ANY situation where Session variables just "disappear?" Note that...
6
by: peter | last post by:
hello, who knows if there is ascript that detects de country or language. I need this to sent for example dutch people to a dutch site and german to a german site. thanx peter
8
by: Brent | last post by:
Does anyone know the best way to detect and track a visitors screen resolution. I know the javascript to detect the users resolution but I am a bit confused on the best way to track and save this....
9
by: Steve Wright | last post by:
Hi I'm developing a webpage that needs to include a different stylesheet depending on the screen resolution. I know that I could read the resolution in javascript and then do some sort of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.