Forum OpenACS Q&A: TCL function for capturing browser type

I have been searching for a way to capture the browser type in a tcl variable.
Most importantly I want to rule out Internet Explorer, so I can display *png files to compliant browsers and *jpg alternatives to IE.
I've spent a couple of nights scouring the net for css/javascript hacks. The problem is that while is quite easy to hide content from standards compliant browsers is not so easy to hide content from IE, in the actual HTML.

I am thinking that a better way would be to capture something like "IE=true" in tcl variable, which then I can use in the actual HTML.
So, is there a way to do this in TCL ?


Pavel Bradut

Posted by Alfred Werner on
If you want to serve PNG images, why use the browser string?

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
Connection: keep-alive
Keep-Alive: 300
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5

String match image/png in the Accept: header!

(headers courtesy of

Posted by Dave Bauer on
set headers [ns_conn headers]
set user-agent [ns_set iget $headers User-Agent]

Check out the AOLserver documentation for ns_conn

Posted by Mike Sisk on
The only real problem with PNG and IE > 5.5 is alpha transparency. If substituting in a JPEG in place of a PNG will give the effect you want you probably don't need to worry about this (since JPEG doesn't support transparency).

If you do need support for transparency and need to avoid all the CSS/PNG land-mines in IE here's two links for possible solutions:

All this hackery should soon be a thing of the past if Microsoft will ever release IE 7 (or everyone switches to Firefox).

As for support of IE version < 5.5 -- I don't think you need to worry about it. From looking at the web stats for the sites I run it appears that for the past year 95%+ of visitors using IE are at version 6. For the remaining 5% using ancient versions of IE, I suspect their browsing experience is so poor that the lack of proper PNG image support is the least of their problems.


Posted by Pavel Boghita on
that's exactly what I meant (working around the lack of transparency support in IE) The site I am building at the moment, is going to have something along the lines "optimised for Firefox". As for the IE users, I found that giving them the equivalent JPEG is good enough.
Thanks for the links. I've tried most of this stuff. JavaScript is not on the cards though. I managed to achieve some filtering with CSS/XHTML, but the best so far has been, Firefox sees the PNG, the IE sees the JPEG but also the PNG, so I got fedup and now I am working to figure out implementing the TCL solution as advised by Dave.

Thanks a lot for all the advice.

Posted by Pavel Boghita on
this is how I've done it in the end (hopefully it will help somebody)

#get user-agent

set headers [ns_conn headers]
set uagent [ns_set iget $headers User-Agent]
if { [regexp "Mozilla/4.0" $uagent] } {
set browser "no_tranparency"
}else {
set browser "transparency"

I have also found this which may help