Email conversation
From | Philip Taylor |
To | Me |
Subject | Using JS to detect if CSS is enabled/disabled in NS4 |
Date | 20 February 2004 16:51 |
Dear Mark -- Your site is brilliant, and I wish I'd
discovered it years ago! However, I cannot find in
it (or anywhere else on the web) some information
which I need as a part of a total re-implementation of
[a London university web site]
I need to be able to ascertain, using JavaScript, whether
stylesheet support has been disabled by the user in the
Netscape 4.79 family; at the moment, I can achieve my
aim only by looking to see if a CSS attribute (e.g.,
color) for a given tag (e.g., <BODY>) exists. This means
that as well as including a standard JavaScript file, I must
also include a standard CSS file and then test in the JS
whether the CSS property exists. I would /like/ to be able
to make the test without any need for pre-existing CSS, and
would welcome any suggestions on your part as to how this
could be achieved. A demo. of the technique I am currently
using (for NS4.79/windows only) can be seen at
[a London university web site]/JS-test.html
Philip Taylor
From | Me |
To | Philip Taylor |
Subject | Re: Using JS to detect if CSS is enabled/disabled in NS4 |
Date | 20 February 2004 19:18 |
Philip,
I really have to wonder why you are going so far out of your way to
support this out-of-date, dead browser, especially such a precise
version of it, but oh well, each to their own ...
Honestly, the best thing to do for netscape 4 is to give it no stylesheet
at all (using @import) and encourage users to upgrade, for their own
sanity, and for the sanity of web developers worldwide.
Still, that doesn't answer the question, so I will try my best:
My instinct would have been to assign a style property to a tag and then
try to read it (or create a hidden layer and count the entries in the
layers array), but you say that is not what you want.
The correct way to do this is to use something like
navigator.preference('browser.enable_style_sheets')
but this requires elevated security privilages, which you probably won't
have, and it prompts the user for permission.
I tried using the various document.classes/document.ids/document.tags
objects, but they are always filled, even if styles are disabled. You see,
netscape 4 still loads and interprets stylesheets, it just doesn't apply
them. so while you should be able to try:
<style>
.notGonnaUse{color:red;}
</style>
<script>
var sheetsEnabled = document.classes.notGonnaUse.all.color;
</script>
It won't actually work,
because NS4 does actually load the stylesheet, so
document.classes.notGonnaUse.all.color is 'red' even if stylesheets are
disabled.
honestly, I think the best method is to create a hidden layer then test
for it:
<div style="position:absolute;"></div>
<script>
var sheetsEnabled = !document.layers || document.layers.length;
</script>
I know this is probably not much help, but you are asking too much
from an archaic browser.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Philip Taylor |
To | Me |
Subject | Re: Using JS to detect if CSS is enabled/disabled in NS4 |
Date | 20 February 2004 22:51 |
Dear Mark -- Very many thanks for your very prompt response.
To answer your perfectly reasonable 'why' question, the main
reason is that it is my own browser of preference (I rely on its
IMAP funtionality as well, and use it as my sole e-mail client).
That apart, it is one of the most difficult browsers support well
using style sheets, and for my own satisfaction I want to ensure
that the new [university] pages work satisfactorily in it as
well as in IE 5.5/6, in the Mozilla/Gecko derivatives, and in
the Opera/Konqueror/... families. As to the precise version,
the code I am developing/testing is intended to map many browser
variants to a single pair of JavaScripts/CSS files, but that
part of the code is simple/trivial and I have therefore just
entered NS 4.79 into its lookup table for the time being; that
table will be augmented as soon as I have re-engineered the
exising material to work under NS 4.79 so as to add support for
all major browsers.
As regards your suggestions, I can see that in essence your
approach is not disimilar to mine; I simply set <BODY> to have
"color: black; background-color: white" and then look to see
if 'document.tags.body.color' is defined. A slightly more
robust approach would be set the colors to (say) #FFFFFE and #000001
and then check for an exact match, but I'm not convinced it is
worth the trouble.
So, very many thanks indeed for taking the trouble to investigate
and to let me know your findings; your efforts are very much
appreciated.
** Phil.