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?
Printable View
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?
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;
}
It appears that JavaScript can set any characterists that it wants, but that does not guarantee that CSS is listening. Hmmm.