Facebook has featured in social media blogs recently for adding a Konami code Easter egg in their home page. In this blog post I show you how to add similar “functionality” to your site using Javascript.
First, the full code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // check to make sure that the browser can handle window.addEventListener if (window.addEventListener) { // create the keys and konami variables var keys = [], konami = "38,38,40,40,37,39,37,39,66,65"; // bind the keydown event to the Konami function window.addEventListener("keydown", function(e){ // push the keycode to the 'keys' array keys.push(e.keyCode); // and check to see if the user has entered the Konami code if (keys.toString().indexOf(konami) >= 0) { // do something such as: // alert('Konami'); // and finally clean up the keys array keys = []; }; }, true); }; |
The script adds a callback function to the keydown event which stores the keycode in the keys array. It then checks the array against the pre-defined konami array (which contains a keycoded version of the Konami code).
Found the Konami code (or any other easter eggs) on the web? Let me know in the comments.

Comments