This nobrainer comes in handy if you truly need JavaScript (did I mention that I actually hate it?)
Doesn’t check if your vistior has JS turned on, just adapts to her/his/its Browser state..
Lets go with standard html
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS Detection</title>
<!-- ensure xternal scripts are executed in the right order) -->
<script src="detect_js.js"></script>
<link rel="stylesheet" href="detect_js.css">
</head>
<body>
<h1>Hi Honey, i'm home!</h1>
<!-- Visible only if JavaScript is DISABLED -->
<noscript>
<div class="noscript-warning">
JavaScript ist deactvated. Some stuff ain't displayed as intended..
</div>
</noscript>
<div class="box">
<p>Active JavaScript changes the look here.</p>
</div>
</body>
</html>
Now create your css
name it as you like, e.g. 'detectjs.css' .
and see that ' nojs , or ' js ' are called .
/*detect_js.css*/
.no-js body { background:tomato;
}
.js body { background:dodgerblue; color:white;
}
.noscript-warning {
background:gold;
color:red;
padding: 1em;
margin: 1em 0;
border-radius: 4px;
}
Finally the heart of the matter
this is actually just a two-liner.
/*detect_js.js*/
document.documentElement.classList.remove('no-js');
document.documentElement.classList.add('js');
From here on, you can go and do things either way.
Jumble with your clients data, spy on them, and torture em with crap,
or do the right thing, whatever it is..
Download » as ZIP
..and today's Checksums are..
- SHA-1:
- 28922cfcada8397e95cfb3a2c0a983faadaf0128
- SHA-256:
- 01a79c2e4d58233fd1bf5f4906a448e17458707f2edb29c061ed8f9b0a553421
- SHA-384:
- 3d3a9946ace292978c574a6743b1d19def0e24d4586f752f45cfd9ae311511c149d28b59925be135c2ab57825f02e33f
- SHA-512:
- 66de2cbd6006be11187b9e9dd951b5268f873121666841d4062f8b216eace4acac404fa7235233b1a2ce6acdc4a6f0148d8cb7b57b897e16047ae3915197d8bb
- MD5:
- 80df6707aa72726e529dbcd7206aee8e
- RIPEMD160:
- eabf099329dc63ef5cd4253dee2cd8886baddb6c