I need to execute a function in JavaScript that will occur only when the user has pressed the Esc key, I would really prefer not to use the <body onKeyPress="function()">, method of doing it and was wondering if there was any other way. Thanks for your help in advance.
You can put it all in a script, if that is what you want: <html> <head> <script type="text/javascript"> window.onload=function() { document.onkeyup = key_event; } function key_event(e) { if (e.keyCode == 27) doStuff(); } function doStuff() { alert("You pressed the ESC key!"); } </script> </head> <body> </body> </html> Code (markup):