[Javascript] detecting CSS capability

Flavio Gomes flavio at economisa.com.br
Mon May 17 09:15:39 CDT 2004


My "gambiarra" way:

<style> someTag.someClass {background-color: navy;} </style>
<someTag id="my_id"> Hi Hi, I'm someTag passing by!! </someTag>
<script> alert(getElementById('my_id').style.backgroundColor) </script>

Ps.: gambiarra is way to do something that "works".. but it's not quite 
the right way ^^

-- 
Flavio Gomes
flavio at economisa.com.br



Paul Novitski wrote:

> Friends,
>
> I'm wondering about the various ways it might be possible to detect 
> whether CSS is functional within a browser, and how dependable any of 
> those checks might be.
>
> Such tests, of course, would not check for the presence of inline 
> styles or a stylesheet link in html, but rather would attempt to 
> determine whether the browser is cognizant of them or acts on them.  
> Here's what I've come up with so far:
>
> A browser might be CSS-enabled if any of the following are true:
>
> - if the collection document.styleSheets exists in the DOM
>
> - If any DOM object has the 'style' property
>
> - If any DOM object has the 'currentStyle' property
>
> - If any DOM object has the 'runtimeStyle' property
>
> It *might* be possible to detect whether any object has been modified 
> by CSS, although my experiments haven't revealed the way.  CSS affects 
> presentation, not object content, and client-side scripts appear not 
> to be aware of the presentation of objects (except through their style 
> settings).  CSS cannot remove or add objects to the DOM for javascript 
> to detect.
>
> CSS2 does include the :before and :after pseudo-elements which appear 
> to insert content, but again this content is purely visual 
> presentation and does not change the innerText or innerHTML of objects 
> to which it is applied.
>
> Any suggestions?
>
> Thanks,
> Paul






More information about the Javascript mailing list