Creating Browser-specific Pages

In some cases, especially with complex pages that take advantage of the latest features in modern browsers, it becomes very difficult to create pages that work properly on all versions. In this case, an easier option is to build separate pages for each 'group' of browsers you intend to support. By a group, we mean browsers that are relatively similar in feature set. The four obvious groups are:

You may decide to combine these into two or three groups, depending on the features you use. In general, with the increasing take-up of the two version 4 browsers, you may decide to provide a simple page for all version 3.x browsers and below, and then individual pages for Navigator 4 and IE4.

Browser-specific Pages and Redirection

Of course, if we're creating different pages for different browsers, we need to redirect the browser to the appropriate page. We can do this client-side, using script, or on the server with ASP. We covered redirection techniques in some depth back in Chapter 2, and we've seen browser detection methods earlier in this chapter. It just remains to combine the two.

Browser-specific Page Redirection on the Client

If we want to use Dynamic HTML, for example, we can create a page each for Navigator 4 and IE 4, and one for the version 3 browsers which uses more generic (non-Dynamic HTML) techniques. Then we can redirect our visitors to the appropriate page automatically from our default page:

...
<SCRIPT LANGUAGE="JavaScript">
<!--
  if (navigator.appName.indexOf('Netscape') != -1)
    if (navigator.appVersion.substr(0, 1) > 3)
      window.location.href = 'nav4_dhtml.htm'
    else
      window.location.href = 'v3_with_script.htm';

  if (navigator.appName.indexOf('Microsoft') != -1)
    if (navigator.appVersion.substr(0, 1) > 3)
      window.location.href = 'ie4_dhtml.htm'
    else
      window.location.href = 'v3_with_script.htm';
//-->
</SCRIPT>
<NOSCRIPT>
  <!-- non script-enabled browser page contents go here -->
  <P>Welcome to our site</P>
  ...
</NOSCRIPT>
...

Browser-specific Page Redirection on the Server

And of course, we can do the same on the server in ASP. This is neater, because the user won’t see the default page being loaded first, followed by the appropriate page that their browser supports. In this next example, we're using the Browser Capabilities component, but you could do the same with plain script, or use something like BrowserHawk instead:

...
<% 
Set objBCap = Server.CreateObject("MSWC.BrowserType")
If objBCap.Browser = "IE" And CInt(objBCap.Version) >= 4 Then 
  Response.Redirect "ie4_dhtml.htm"
ElseIf objBCap.Browser = "Netscape" And CInt(objBCap.Version) >= 4 Then 
  Response.Redirect "nav4_dhtml.htm"
ElseIf objBCap.javascript = True Then 
  Response.Redirect "v3_with_script.htm"
End If 
%>
<!-- non script-enabled browser page contents go here -->
<HTML>
...
<P>Welcome to our site</P>
...

© 1998 by Wrox Press. All rights reserved.