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
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 )
Thanks for the responses. I suppose I was hoping that there was some sort of content negotiation thingy, like ACCEPT-CSS, available. I'm thinking that the best solution would be to move it into javascript and let it choose which style sheet(s) to load. I know its not much of a CPU load, but the inefficiency of doing this song and dance with every page read annoys me. Mebbe fiddling with the cookie from javascript before the page gets processed would work, at least for the session? Phil Harris wrote:
I came up with a different solution that covers more browsers (mainly Netscape/IE)
...
Phil phil.harris@zope.co.uk
...
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.
...
Please let me know if you have any questions or suggestions for improvement.
Regards, Ben
-- John Edstrom | edstrom @ slugo.hmsc.orst.edu http://bubo.hmsc.orst.edu/~edstrom
John Edstrom wrote:
Thanks for the responses. I suppose I was hoping that there was some sort of content negotiation thingy, like ACCEPT-CSS, available. I'm thinking that the best solution would be to move it into javascript and let it choose which style sheet(s) to load.
I know its not much of a CPU load, but the inefficiency of doing this song and dance with every page read annoys me. Mebbe fiddling with the cookie from javascript before the page gets processed would work, at least for the session?
It is much better to have the CPU horsepower distributed across the thousands of CPUs that will visit your site, rather than trying to have your single little server trying to do the processing for all those users. Think of it as a cluster!!! --sam -- Sam Gendler Chief Technology Officer - Impossible, Inc. 1222 State St. Suite 250 Santa Barbara CA. 93101 w: 805-560-0508 f: 805-560-0608 c: 805-689-1191 e: sgendler@impossible.com
I would like to warn the community about serving multiple pages up based on the exact same request url (which is what the code below can contribute to). There are an awful lot of network caches out there, and many of them intercept requests transparently, without informing the client. These caches will cache the first document that it gets a request for, and then serve it for all subsequent requests. This means that if a 3.0 browser grabs this page first, all subsequent 4.0 browsers will get the non stylesheet page. This is bad. There are mechanisms built into http/1.1 (netscape isn't there yet, and I don't know about Opera) that allow a server to mark a page as varying on a particular header (Vary: user-agent, or something similar), which should cause a cache to cache different copies of the object for each user-agent request that it sees. However, most caches ignore this command, since few authors do this anymnore (they learned the hard way). In general, it is best to detect css support in javascript, or design pages that work with or wothou CSS support. In other instances, if you must do a detection, get the results and then issue a redirect to the correct page (make sure it is a temporary redirect, not a permanent one, since the permanent redirect is considered a cachable object in most caches). If you thin that this is a non-issue, just be aware that AOL's entire network is cached by transparent caches, and that is 20 million web browsers of all shapes and sizes. --sam Ben Glazer wrote:
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 )
-- Sam Gendler Chief Technology Officer - Impossible, Inc. 1222 State St. Suite 250 Santa Barbara CA. 93101 w: 805-560-0508 f: 805-560-0608 c: 805-689-1191 e: sgendler@impossible.com
participants (4)
-
Ben Glazer -
John Edstrom -
Phil Harris -
Sam Gendler