How to invoke javascript event onKeyDown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sshan
    New Member
    • Jul 2010
    • 1

    How to invoke javascript event onKeyDown

    I need to invoke javascript event onKeyDown, which should get invoked when we press any key from anywhere of the page. currently I am callin like this:


    Code:
    <head>
    <script type="text/javascript">
    //document.onKeyDown=isBack(event);
    function isBack(event)
    {
    	alert('hit a key');
    }
    </script>
    </head>
    
    <body onKeyDown="isBack(event);">
    
    <input type="text" id="myid">
    </body>
    Is ther any way to invoke it, other than from body. Like the line (//document.onKeyD own=isBack(even t);) . will it work?
    Last edited by Dormilich; Jul 5 '10, 05:56 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Like the line (//document.onKeyD own=isBack(even t);) . will it work?
    that line will definitely not work (at least not as intended)

    you can attach the handler to any element/object you like, but to work global you need it to attach to window or body at least.

    Comment

    Working...