Search this site!

Return to the CSB Support home page
How can I determine the screen resolution a visitor is using?

Problem:   Visitors may view your web site with their monitor set at different screen resolutions.  The two most common ones are 800x600 and 1024x768.  You may want to create specific, unique pages in your web site tailored to display properly in different screen resolutions.

To do this, you need to determine which screen resolution your visitor is using, and you can then automatically direct them to the appropriate page.

The following example comes from a PC Magazine article.


Step 1:
Let's verify that we can determine the browser resolution you (the visitor) are using.
See if your screen resolution is properly displayed:

And here is the code I used to do it:

document.write("screen width=" + screen.width + "<br>");
document.write("screen height=" + screen.height + "<br>");
document.write("available screen width=" + screen.availwidth + "<br>");
document.write("available screen height=" + screen.availheight + "<br>");

Step 2:
Now let's see what code we need to have our web site automatically go to a specific page based on the visitor's screen resolution. The code listed is NOT exactly what was posted in the PCMag article, as I found corrected some coding logic errors:

if (screen.width<=640)
else if (screen.width<=800)
else if (screen.width<=1024)
else location.href="size1280.htm";

Step 3:
Let's see if it really works!

Click here to go to page based on your current screen resolution