W3C home > Mailing lists > Public > www-talk@w3.org > March to April 1995

Re: distinguishing browser types

From: Royston Shufflebotham <rws@ukc.ac.uk>
Date: Fri, 21 Apr 1995 12:46:12 +0100
To: rs@sun09.cci.com, www-talk@www10.w3.org
Message-Id: <5746.798464772@cypress.ukc.ac.uk>

Rick> I wonder if someone could point me to some code that would show
Rick> how to serve up data tailored to a particular browser.
Rick> Specifically, I would like to serve a file with some tables as
Rick> <PRE> blocks for browsers that do not get tables yet, and html3
Rick> table stuff for browsers that do.
Rick> Thanks In advance.
Rick> Rick Silterra

I use some code like this in a page on our server.

The bit of code which detects which browser is being used looks like:


if ($user_agent=~/Mozilla/) {   # Netscape
    if ($version>=1.1) {
} elsif ($user_agent=~/Arena/) { # Arena
} elsif ($user_agent=~/NCSA Mosaic/) { # Mosaic
    if ($version>=2.5) {

Currently, this only spots Netscape v1.1 or above, Mosaic v2.5 or
above, or any version of Arena..
(btw - you'll need Perl5 for the non-greedy regexps there)

Just before the data gets printed out, I prepare one of two
templates for a printf:

$template="%-23s %5s %-15s %-5s %-25s %5s\n";
<TD align=left><P>%s</P></TD>
<TD align=left><P>%s</P></TD>
</TR>\n" if $html3_table_support;

Then, this section of code prints out the heading line, if necessary:

if (!$head) {
    if ($html3_table_support) {
        print "<TABLE>\n";
        print "<TR><TH ALIGN=left><P>Name</P></TH>\n";
        print "<TH><P>Phone</P></TH>\n";
        print "<TH><P>Last seen when?</P></TH>\n";
        print "<TH><P>Room</P></TH>\n";
        print "<TH><P>Description</P></TH>\n";
        print "</TR>\n";
    } else {
        print "<PRE>\n";
        printf $template, "Name", "Phone", "Last seen when?","Room", "
        print "\n";

To the print the individual rows in the table:

printf $template, ${$info}{"surname"}.", ".${$info}{"forename"},
${$info}{"phone"}, $nicetime, ${$info}{"room"}, $infomsg;

Then, obviously, at the bottom of the table, I close up the <PRE>
or <TABLE> section.

You can see this code in action at 

Hope this is of use,

Royston Shufflebotham  | Computing Laboratory, The University,
Postgraduate Research  | Canterbury, Kent, CT2 7NF, UK
Mobile Computing       | Tel.: (+44) [0]1227 764000, Ext.3822
Received on Friday, 21 April 1995 07:48:47 UTC

This archive was generated by hypermail 2.4.0 : Monday, 20 January 2020 16:08:16 UTC