Javascript examples for DOM:Key Event
Handle key down event on document
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/* w w w. j a v a 2 s .co m*/ document.addEventListener("keydown", keyDownTextField, false); function keyDownTextField(e) { var keyCode = e.keyCode; if(keyCode==13) { console.log("You hit the enter key."); } else { console.log("Oh no you didn't."); } } }); </script> </head> <body> </body> </html>