www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Detection Method...

  1. #1
    Join Date
    Aug 2010
    Posts
    51

    resolved [RESOLVED] Detection Method...

    Is there a way to detect via JavaScript if CSS is enabled?
    Simply put what I want to do is stop a default load action if CSS is disabled so that the result cannot ruin the "beauty" of the page.
    E.g. IMG tag starts with blank.gif as SRC and when page loads SRC is changed to randomly selected URL but if CSS is disabled this makes the page ugly thus the stopping of the action.
    Last edited by awsdert; 11-12-2010 at 05:31 PM. Reason: Made more readable

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<title>css test</title>
    <style type='text/css'>
    	#nocss {display:none;}	
    </style>	
    </head>
    <body>
    
    css test
    <div id='nocss'> &nbsp;</div>	
        
    <script type='text/javascript'>
    
    var hasCSS=true; //default is true (98&#37;+)
    function el(tid) {return document.getElementById(tid);}
    
    window.onload= function (){
    
       hasCSS=!el("nocss").offsetWidth;
    
     alert("CSS available: "+hasCSS);
    	
    }
    </script>
    </body>
    </html>
    tested in ff3.6

  4. #4
    Join Date
    Aug 2010
    Posts
    51

    Talking Sorted!

    Thanks, I'm going with something like this:
    Code:
    function js.test.css () {
      var r = false;
      if (document.all || document.layers || document.getElementById) {
        var e = js.id(arguments[0]);
        if (e && e.offsetWidth) { r = true; }
      } return r;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles