[ic] New UserTag: detect-browser

Jeff Carnahan jcarnahan@networq.com
Sun, 15 Apr 2001 17:44:57 -0700


Another usertag that some people may enjoy. If you're concerned with the
layout of your pages on various combinations of browsers and operating
systems, you may want to check out using HTTP::BrowserDetect within your
Interchange code.

See the documentation below for another example of how to use it.

--
Jeff Carnahan - jcarnahan@networq.com

--SNIP------------------------------------------------------------------
#
# $Id: detect-browser,v 1.1 2001/04/16 00:44:05 jcarnahan Exp $
#
# UserTag detect-browser - see documentation for more information
#
# Copyright 2001 by Jeff Carnahan <jcarnahan@networq.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA.

UserTag detect-browser Documentation <<EOD

NAME:       detect-browser

FUNCTION:   Instantiates a HTTP::BrowserDetect object for later use.

TESTED:     Tested on Interchange 4.6.4 -- should work on all future
            versions without any changes.

USAGE:      [detect-browser]

            There are no parameters.

DISCUSSION:

This tag will instantiate a HTTP::BrowserDetect object you can use to
determine what type of browser & operating system (among other things)
the user is viewing your web pages with.

This can be very useful when you want to include content or change the
layout of your site based on what standards the user's browser supports.

The instantiated object is stored among the scratch variables. It is
named "BrowserDetect". The usertag will not return any output.

For example, I'm using a bit of JavaScript which will provide my users
with a dynamic drop-down menu. However, if a Macintosh user running
Netscape visits my site, I need to adjust the menu's slightly.

To do this, my page looks like:

  
    
    [if explicit][condition]
        my $bt = $Scratch->{BrowserDetect};
        return ($bt->netscape && $bt->mac);
    [/condition]
        
        
    [else]
        
    [/else]
    [/if]
  
   ... 

Note that you will need to have the HTTP::BrowserDetect Perl module
already installed. If you do not have it installed, the best way is
to login as root, and run:

# perl -MCPAN -e shell

to load the Perl CPAN shell. Then type "install HTTP::BrowserDetect" to
download and install the module. If you do not have root access, you can
download the module at your local CPAN archive.

For more information about what you can do with HTTP::BrowserDetect,
stop by:

http://theoryx5.uwinnipeg.ca/CPAN/data/HTTP-BrowserDetect/

EOD

UserTag detect_browser Routine <<EOF
sub {

    use HTTP::BrowserDetect;
    $Scratch->{BrowserDetect} = new
HTTP::BrowserDetect($Session->{browser});
    return '';
}
EOF