The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Programmers, Prepare Your Pranks!

posted under category: General on March 30, 2005 by Nathan

As a friendly reminder that April Fool's Day is just around the corner, and better yet, it's a weekday, for those of you who run any intranets, here's a little code to get you going. Just a simple little trick, but it gets the job done. Click below to view it (just a little CF, mostly Javascript).


<cfif not dateCompare(now(),"4/1/#year(now())#","d")>
<script>
var r = Math.round(Math.random()*100);
function dang() {if(r==25){document.bgColor=getRandColor();setTimeout("dang();",50);}}
function getRandHex() {var b16=new Array(1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f');return b16[Math.floor(Math.random()*15)];}
function getRandColor() {var c="";while(c.length<6){c+=getRandHex();}return c;}
document.onload=dang();
</script>
</cfif>

Try it out. Doesn't do anything? There's a 1% chance that it will, but once or so out of a hundred hits, you'll get a random color flashing page background. Refresh and it's gone! Pretty sneaky, no?

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.