sneamia Posted September 15, 2007 Share Posted September 15, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script language="javascript" type="text/javascript"> function storeLetters(ev) { if (window.event) { keynum = ev.keyCode; } else if (ev.which) { keynum = ev.which; } keychar = String.fromCharCode(keynum); if (sofar == undefined) { sofar = keychar; } else { sofar += keychar; } if (sofar.length > 10) { alert(sofar); } } var sofar; </script> </head> <body onkeydown="storeLetters(event);"> <textarea></textarea> </body> </html> This is what I have. When a key goes down, it stores that letter in the variable 'sofar.' After ten letters, it alerts with what I've typed so far. Would it be possible to have this work on something being typed inside an frame? Link to comment https://forums.phpfreaks.com/topic/69425-js-keylogger/ Share on other sites More sharing options...
emehrkay Posted September 15, 2007 Share Posted September 15, 2007 remove the onkeydown from body and place it on your iframe like so <iframe ... id="iframeID"> in the head add this onload = function(){ document.getElementById('iframeID').onkeydown = storeLetters(event); } that should work Link to comment https://forums.phpfreaks.com/topic/69425-js-keylogger/#findComment-349259 Share on other sites More sharing options...
sneamia Posted September 17, 2007 Author Share Posted September 17, 2007 It seems I cannot access 'event' from the head. event is not defined... Line 25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script language="javascript" type="text/javascript"> function storeLetters(ev) { if (window.event) { keynum = ev.keyCode; } else if (ev.which) { keynum = ev.which; } keychar = String.fromCharCode(keynum); if (sofar == undefined) { sofar = keychar; } else { sofar += keychar; } if (sofar.length > 10) { alert(sofar); } } var sofar; onload = function(){ document.getElementById('iframeID').onkeydown = storeLetters(event); ****Line 25**** } </script> </head> <body> <iframe src="test.php5" id="iframeID"></iframe> <textarea></textarea> </body> </html> Link to comment https://forums.phpfreaks.com/topic/69425-js-keylogger/#findComment-350111 Share on other sites More sharing options...
emehrkay Posted September 18, 2007 Share Posted September 18, 2007 you dont need to pass in event to the function in the onload function, change it to = storeLetters; Link to comment https://forums.phpfreaks.com/topic/69425-js-keylogger/#findComment-350319 Share on other sites More sharing options...
sneamia Posted September 19, 2007 Author Share Posted September 19, 2007 you dont need to pass in event to the function in the onload function, change it to = storeLetters; The function takes the event that is passed into it and then gets the keycode from that. Is there any way to modify the JS to make it work? Link to comment https://forums.phpfreaks.com/topic/69425-js-keylogger/#findComment-351406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.