Javascript examples for DOM:Key Event
Call method when enter key pressed anywhere in page
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/* ww w. java2 s . c o 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>