Now it's time to check for the browser using JavaScript. We can do that quite simply:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
if(navigator.appName.indexOf("WebTV") != -1)
document.write("You have WebTV");
else
document.write("You're using a normal Web browser");
//-->
</SCRIPT>
Keep in mind that there is currently a bug in WebTV's browser that makes it think it is a Netscape browser. The way to deal with this problem is to test for WebTV before you test for Netscape.
Now you must decide if you're going to write the page dynamically using JavaScript--based on what browser you find, or just refer the browser to a specific page designed for that particular browser. In the future, I predict that everyone will be using XML for their Web pages, and the browser will receive a subset of the page, or the whole page, depending on the device making the request. A Palm Pilot would get a very small version, WebTV would get a bit more, and a standard Web browser would get the whole thing. Until then, however, you'll have to make the choice ahead of time using standard techniques.
Now we'll show you how to detect the browser using a CGI script written in Perl. We'll detect the browser by looking at its HTTP_USER_AGENT variable. If the browser is a WebTV browser, the user is sent to webtvpage.html; if not, they'll go to otherbrow.html.
Again, what you do once you have detected the browser depends on your skills and whether or not you want to dynamically create your page or just send the user to a separate page. Now once we get our user where we want them, what can we do about the difference between the resolution of a TV set and that of a computer screen?