Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting CSS compatibility

Status
Not open for further replies.

The

Programmer
Jul 30, 2001
92
0
0
CA
Is there a way to detect wether the user's browser supports CSS? Thanks.
 
Not that I know of... But you can find lists on the internet where you can find which browser supports what kind of programming, for instance table, or CSS....

Visit
 
Using JavaScript you could employ what is referred to as a "DOM sniffing" technique.

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!-- //
if (document.getElementById) {
alert(&quot;CSS supported&quot;)
}else{
alert(&quot;CSS not supported&quot;)
}
// --></script>

Clive
 
Use feature sensing rather than trying to test for a specific browser as the name of browsers changes and your code may not!

CliveC's solution is good start. He's using feature sensing to see if the browser can get elements from the DOM structure by using getElementById(&quot;id&quot;) but this does not prove that the browser can do the specific thing you need (this is known as 'over abstraction').

So, if you wanted to change the color of an element called 'foo', and pop up a window if that fails:

Code:
if (!(document.getElementById(&quot;foo&quot;).style.color = #0000ff))
        alert(&quot;Get a better browser!\nYour browser does not support some basic CSS methods!&quot;)'

www.keteracel.com
banner-small.png



keywords: javascript css DOM feature sensing
 
oh, hang on, you just want to know if a browser supports it... why?

You should assume that browsers can support CSS1 at least. If they don't support CSS1 then they probably won't support javascript (definately not the DOM functions) and so their browser is useless to you as a developer and them as a user...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top