www.webdeveloper.com
Results 1 to 3 of 3

Thread: JavaScript detect CSS

  1. #1
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    598

    JavaScript detect CSS

    Is there a way for JavaScript to detect whether or not CSS is active? In some browsers, you can turn CSS off. Can JS check it?

  2. #2
    Join Date
    Mar 2009
    Posts
    512
    Hello--

    There might be a much easier way but you could just run a brute force type test such as:

    Code:
    function cssWorks(){
         var div, width, flag = true;
         div = document.createElement('div');
         document.body.appendChild('div');
         div.style.width = "20px";  //set it
         if (div.offsetWidth != 20){  //see if it worked
             flag = false;
         }
         div.style.width = "40px";  //repeat on the off chance it was 20px anyway
        if (div.offsetWidth != 40){
             flag = false;
         }
         document.body.removeChild(div);  //remove
         return flag;
    }

  3. #3
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    598
    It appears that JavaScript can set any characterists that it wants, but that does not guarantee that CSS is listening. Hmmm.

Thread Information

Users Browsing this Thread

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

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