[Zope] RE: zope/style sheets

Ben Glazer glazer@scicomp.com
Tue, 1 Feb 2000 14:50:31 -0600


> I saw your Nov 1999 post about sensing browser abilities.
>
> Did you ever get an answer?

No, I didn't.  :(  However, I did come up with a workable (though certainly
not elegant) solution on my own.  (I hope you don't mind that I'm copying
this message to the Zope list -- this might be useful to other people.)

What I currently do (which is a bit of a kludge) is check to see whether the
client's browser reports itself as compatible with Mozilla/4 or Mozilla/5
(Netscape Navigator, MS Internet Explorer, and Opera all pass this test).
All I want to know is whether the browser includes ANY support for CSS,
rather than what level of CSS support is provided.  Your needs may be
different.

In case you're interested, the specifics of my implementation follow.

I've written an external method called supportsCSS:

	import re

	def supportsCSS(self):
	    """Checks (sort of) whether requesting browser supports stylesheets."""

	    if re.match('Mozilla/[45]', self.REQUEST.environ['HTTP_USER_AGENT']):
	        return 1
	    else:
	        return 0


Note that the version string test is hard-coded as a very simple regex.
This (unfortunately) needs to be kept in mind for future browser changes
(e.g. Mozilla 6.0).

In my standard_html_header, I include something like:

	<dtml-if supportsCSS>
	    Supports CSS.  (Feel free to include stylesheets, etc.)
	<dtml-else>
	    No CSS support.  :(
	</dtml-if>


Please let me know if you have any questions or suggestions for improvement.


Regards,
Ben