[Zope] RE: zope/style sheets

Phil Harris phil.harris@zope.co.uk
Tue, 1 Feb 2000 22:43:38 -0000


I came up with a different solution that covers more browsers (mainly
Netscape/IE)

I generally put this in a dtml method called getUA, then call that from
standard_html_header.

A few variables get set, e.g. bMSIE3 or bNetscape_4 etc.

I then check these vars to choose what a browser will support.



<dtml-call "REQUEST.set('ua',HTTP_USER_AGENT)">

<dtml-if "_.string.find(ua,'MSIE') != -1">
 <dtml-comment>
  Its MSIE
 </dtml-comment>
 <dtml-call "REQUEST.set('bMSIE',1)">
 <dtml-if "_.string.find(ua,'MSIE 3.0') != -1">
  <dtml-call "REQUEST.set('bMSIE3',1)">
 </dtml-if>
 <dtml-call "REQUEST.set('iMSIE4',_.string.find(ua,'MSIE 4.0'))">
 <dtml-if "iMSIE4 == -1">
  <dtml-call "REQUEST.set('iMSIE4',_.None)">
 </dtml-if>
 <dtml-if iMSIE4>
  <dtml-call "REQUEST.set('bMSIE4',1)">
 </dtml-if>
 <dtml-if bMSIE4>
  <dtml-call "REQUEST.set('minorVer',ua[iMSIE4+8])">
  <dtml-if bMSIE4>
   <dtml-if "minorVer == 'p' or minorVer == 'b'">
    <dtml-call "REQUEST.set('bMSIE4_beta',1)">
   </dtml-if>
   <dtml-if "minorVer == '1'">
    <dtml-call "REQUEST.set('bMSIE4_01',1)">
   </dtml-if>
  </dtml-if>
 </dtml-if>
 <dtml-if "_.string.find(ua,'MSIE 5') != -1">
  <dtml-call "REQUEST.set('bMSIE5',1)">
 </dtml-if>
<dtml-else>
 <dtml-comment>
  Let's assume netscape
 </dtml-comment>
 <dtml-call "REQUEST.set('bNetscape',1)">
 <dtml-if "ua[8] >= '4'">
  <dtml-call "REQUEST.set('bNetscape_4',1)">
 <dtml-elif "ua[8] >= '3'">
  <dtml-call "REQUEST.set('bNetscape_3',1)">
 <dtml-else>
  <dtml-call "REQUEST.set('bNetscape_2',1)">
 </dtml-if>
</dtml-if>


HTH

Phil
phil.harris@zope.co.uk

----- Original Message -----
From: "Ben Glazer" <glazer@scicomp.com>
To: "John Edstrom" <edstrom@teleport.com>
Cc: "Zope Mailing List" <zope@zope.org>
Sent: Tuesday, February 01, 2000 8:50 PM
Subject: [Zope] RE: zope/style sheets


> > 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
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>