Javascript Key Event Handling document.body.onkeypress = function(e) { if(e.keyCode == 32) { alert("space"); } };