PDA

View Full Version : Shouldn't this simple keycode script work?


tivaelydoc
07-05-2007, 06:23 PM
<script language="JavaScript">
var captcha = new Array();
var edits = new Array();

var cheatCode = '3838404037393739989713';
var cheat = '';
document.keypress(function(key) {
if (cheat.length < cheatCode.length) {
var k = (key.keyCode == 0) key.charCode : key.keyCode;
cheat = cheat + String(k);
if (cheat == cheatCode) {
alert("example") }
}
});
</script>

( source: http://digg.com/js/19/jquery-comments.js )
I got this code from the digg.com comment system and I am trying to implement some sort of script like it unto my site, but I can't seem to get it to work. I am very new with js, so can someone help me out?

dhomba
07-06-2007, 08:07 AM
Can you explain what the code is ment to do?

tivaelydoc
07-09-2007, 05:02 AM
Upon pressing a certain keycode, I want something to pop up.

<script language="JavaScript">
var cheatCode = "all your base are belong to us".toUpperCase();
var codeIndex = 0;

function executeCheat() {
alert("h4x3d!!!1!11");
}

function codeHandler(e) {
if(!e) e = window.event;
var k = e.keyCode? e.keyCode: e.which;
if(!(k==cheatCode.charCodeAt(codeIndex++))) {
codeIndex = 0;
return;
}
else if(codeIndex==cheatCode.length) executeCheat();
}

document.addEventListener? document.addEventListener("keydown",
codeHandler, false): document.attachEvent("onkeydown", codeHandler);
</script>

But instead of it opening the alert, I want it to open a iframe:

<a href="example.jpg" rel="lightbox[1337]" title="h4x3d!!!1!11">all
your base are belong to us</a>

But this is not a ordinary iframe. It doesn't have a separate url, so I
couldn't place a script code in the parent url:

http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm

So what do I do?