A project I’m finishing off involves a simple little front end that I’ve decided to implement using some DHTML. As I was reading up on JavaScript’s setTimeout method as part of my DHTML research, an interesting thought crossed my mind: would it be possible to make a strobe light out of that old archaic CRT monitor sitting on my closet floor and such a weak (as in weakly typed) language as JavaScript?

Well, I decided to give it a try and it actually worked out pretty well — although it did give me a mild headache after I had the not so keen idea to stare directly at it for a few seconds. Be warned that if you’re that one other extremely unlucky person, you might just ruin your equipment (or cause someone you know to have a seizure) by running a script as powerful as this one.

Here’s the code you need to make use of that old dust magnet.


<html><head>
<title>Strobe</title>

<script>
<!-- If you're extremely unlucky, you may break your equipment, or worse, have a seizure -->
function toggleBgColor()
{
  document.bgColor = document.bgColor == '#ffffff' ? '#000000' : '#ffffff';
  setTimeout('toggleBgColor()', 75); //in milliseconds
}
</script>
</head>

<body onLoad='toggleBgColor();'>
</body></html>

Just save the code as a webpage (text file that ends in “.html”) and open it up in your favorite semi-modern web browser to let the fun begin. Pretty simple, huh?

Can you think of anything better to do with that old monitor than make a strobe out of it? (Or do you know of any other JavaScript hacks that could potentially be hazardous to your health?)