if ( event.keyCode == 32 ) { alert ('you pressed space!'); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> document.onkeydown = docKeyDown; function docKeyDown(e) { if(!e) e = window.event; if(e.keyCode == 32) alert("Pressed space!!!"); } </script> </head> <body> Blah blah blah </body> </html>