Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Detecting WebTV

November 22, 1999

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.

#!/usr/local/bin/perl -w

$webTVpage = "/webtvpage.html";
$others = "/otherbrow.html";

if ($ENV{'HTTP_USER_AGENT'} =~ /WebTV/)
{
   $location = $webTVpage;
}

else # all others
{
   $location = $others;
}

print "Location: $location\n\n"; 
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?



Up to => Home / Authoring / Design / WebTV




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers