Developers often tailor content to specific audiences. Made common when Netscape Navigator and Microsoft® Internet Explorer supported different DHTML tags and elements, %u201Cmirrored%u201D sites that were altered to accommodate each client browser were a perfect solution. Users were redirected with a simple script that detected the browser and immediately sent the user to the proper home page. It was instantaneous and therefore transparent to most users.
A browser %u201Csniffer,%u201D or detector, is a useful tool for customizing Web content for different browsers. There are countless code examples scattered throughout the development community on the Web. Following are just two simple examples of codes for detecting the TV browser.
The JavaScript code in this example uses the navigator object, which contains information about the software a viewer is using to view a Web page.
<SCRIPT LANGUAGE="JavaScript">
<!--
if(navigator.appName.indexOf("WebTV") != -1) //WebTV detected
document.writeln("How do you like that WebTV?");
else //Non-WebTV detected.
document.writeln("When are you going to get WebTV?");
//-->
</SCRIPT>
This CGI script separates our browser from other browsers. The following example noted is a Perl CGI solution. This script detects the browser visiting the site by looking at its HTTP_USER_AGENT string. If that string contains %u201CWebTV%u201D then the browser is redirected to /tv_index.html. Otherwise, the browser is redirected to /ie_index.html.
#!/usr/local/bin/perl -w
$webTV_url = "/tv_index.html";
$other_url = "/ie_index.html";
if ($ENV{'HTTP_USER_AGENT'} =~ /WebTV/)
{
$location = $webTV_url;
}
else # all others
{
$location = $other_url;
}
print "Location: $location\n\n";
Browsers are often referred to by the technical term %u201Cclient.%u201D This refers to an application that processes something locally, as opposed to processing an instruction on a remote server. When a browser makes a request for information across a network it exposes, among many other things, two pieces of identification: the browser%u2019s name and software version. By using a simple JavaScript a developer can use this information for any number of purposes, but it is often used for customizing content for a specific browser.
The TV browser accesses the Internet through proprietary proxy servers. When a browser requests a page from the Internet the Web server %u201Csees%u201D the request as coming from our proxy server. The following tables illustrate the response to the indicated query:
Query | Response |
userAgent | Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0) |
appVersion | 4.0 (WebTV;2.6) |
appName | WebTV Classic receiver (Classic) or WebTV Plus receiver (Plus) |
Alias appName | Microsoft® Internet Explorer |
Some early models of the WebTV Classic receiver return earlier version numbers.