I need to check if browser JavaScript is off, then display a error div instead of the body, how can I do this?
How to detect if browser JavaScript is off and display a notice
2.3k views Asked by erfaan At
4
There are 4 answers
1
On
@roryf's solution is a good approach, although it is dependent on jQuery, and if the domloaded event fires a little late you can get a 'flash' of the no-js content.
The following will remove the html.no-js
class before the body has rendered:
<!DOCTYPE html>
<html class="no-js">
<head>
<script>
if (document.documentElement) {
var cn = document.documentElement.className;
document.documentElement.className = cn.replace(/no-js/,'');
}
</script>
</head>
Of course, this is usually a bad idea, but I hope you've already considered that.