You are not logged in Log in Join
You are here: Home » Members » jmeile » Detecting the browsers' name and version » howto_view

Log in
Name

Password

 

Detecting the browsers' name and version

 

Created by jmeile . Last modified 2004-05-13 14:44:46.

Python script to detect browsers' name and version

I took the original idea from: Determine Browser *type and improved it. The difference between the previous approach and mine is that I don't scan the HTTP_USER_AGENT string, I split it into several parts and store them in a list.

You just need the following python script:

Id: getBrowser
Title: Returns the browser name and version
Parameter List: REQUEST=None


I know the code is ugly, but it's not my fault that agent strings aren't standard

Calling it:

  • From the web:
    http://mysite.com/getBrowser or
    http://localhost:8080/getBrowser

  • From a python script:
    myVar=context.getBrowser()
    browser=myVar[0]
    version=myVar[1]

  • From a dtml-method:
    <dtml-let myVar="getBrowser()" browser="myVar[0]" version="myVar[1]"> Do something here </dtml-let>

  • Tal:
    <span tal:define="myVar python:here.getBrowser();
    browser python:myVar[0];
    version myVar[1]">
    Do something here </span>

Limitations:

It will only work with Netscape >=4 (Somebody tested it with Ns 3.x and it worked), Microsoft Internet explorer, Opera, Galeon, K-Meleon >=0.7, Konqueror, lynx, links, wget and Mozilla/gecko compatible browsers. With the rest you will see browser='unknown', version='0'. If you want more browsers, you'll have to add them.

Special thanks to:

Volker Zausch for its idea of merging the two methods into one.

Changes:

* Mozilla-Geko browser returned the false version number (fixed).

If there is a bug or something is missing, please let me now:
Here you'll find more how-tos and products I've published.