[Zope] Browser Detection

Olivier Deckmyn odeckmyn.list@teaser.fr
Fri, 17 Mar 2000 10:32:31 +0100


The Netscape part works fine on my FreeBSD/Netscape box.
The IE doesn't work on my Win98/IE5 box...



----- Message d'origine -----
De : Phil Harris <phil.harris@zope.co.uk>
À : Tom Scheidt <tom@falsemirror.com>; <zope@zope.org>
Envoyé : jeudi 16 mars 2000 22:46
Objet : Re: [Zope] Browser Detection


> Tom,
>
> Try this (only slightly tested)
>
> <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>
>
>
> Include this in your standard_html_header and then use the variables in
your
> pages as normal,so:
>
> <dtml-if bNetscape_4>
>   do netscape specific stuff
> <dtml-elif bMSIE4_01>
>   do IE specific stuff
> </dtml-if>
>
> HTH
>
> Phil
> phil.harris@zope.co.uk
>
> ----- Original Message -----
> From: "Tom Scheidt" <tom@falsemirror.com>
> To: <zope@zope.org>
> Sent: 16 March 2000 18:36
> Subject: [Zope] Browser Detection
>
>
> > Is there a way to write a <dtml-if> for browser detection, like:
> >
> > <dtml-if (User Agent is Netscape 4.5)>
> > Use this
> > <dtml-elif (User Agent is Internet Explorer 5.0)>
> > Use this
> > </dtml-if>
> >
> > Thanks in advance.
> >
> > *************************
> > Tom Scheidt
> > www.falsemirror.com
> > tom@falsemirror.com
> > *************************
> >
> >
> > _______________________________________________
> > 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 )
>
>
> _______________________________________________
> 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 )
>
>