Oftentimes, the question is asked how one may detect a web user's screen resolution and redirect them to a page designed specifically for that resolution. Below is a JAVA-based solution of doing so as well as a discussion on why you shouldn't do so.
It is the goal of every web author to create a site that is useful and informative, and at the same time, visually appealing. Often, with the web, this is not so easily done. This is because you don't know how your visitor's computer will be setup. Is the screen resolution higher then your own? Will the website have too much white space as a result? Or perhaps it will appear cramped because the visitor's screen resolution is set smaller than your own.
JAVA can provide you with a solution to your problem. The screen resolution can be found via the java.awt.Toolkit class and the "redirection" can be accomplished via the java.applet.AppletContext.showDocument() function. The source code follows or you can download the precompiled applet (zipped along with HTML and TXT documentation).
import java.applet.*;
import java.awt.*;
import java.net.*;
public class ScreenRes extends java.applet.Applet {
public void start() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
String file = null;
URL url = null;
switch(screenSize.width) {
case 640: file = "640.html"; // 640x480
break;
case 800: file = "800.html"; // 800x600
break;
case 1024: file = "1024.html"; // 1024x768
break;
case 1280: file = "1280.html"; // 1280x1024
break;
case 1600: file = "1600.html"; // 1600x1200
break;
default: file = "other.html";
break;
}
try { url = new URL(getDocumentBase(), file); }
catch ( MalformedURLException e) {
url = null;
}
if (url != null) {
getAppletContext().showDocument(url);
}
}
}
...and insert the following tag into the BODY of your HTML document:
<APPLET CODE="ScreenRes.class" WIDTH=1 HEIGHT=1></APPLET>
The above applet will cause a JAVA-enabled browser, with JAVA turned on, to redirect the user to 640.html if the screen resolution is 640x480, to 800.html if the screen resolution is 800x600, etc. Go ahead... give it a try.
The ability to detect a user's screen resolution and redirect her accordingly would seem a very compelling thing to do. However, it has several very serious reasons as to why you should not:
Your best bet is to markup your document intelligently. Do not design for a specific resolution or even a specific number of colors. Rather, design your page for everyone using intelligent, degradable markup.
| [Section Index] | [Home Page] |