469,934 Members | 1,924 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

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:

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3. //document.onKeyDown=isBack(event);
  4. function isBack(event)
  5. {
  6.     alert('hit a key');
  7. }
  8. </script>
  9. </head>
  11. <body onKeyDown="isBack(event);">
  13. <input type="text" id="myid">
  14. </body>
Is ther any way to invoke it, other than from body. Like the line (//document.onKeyDown=isBack(event);) . will it work?
Jul 2 '10 #1
1 2010
8,652 Expert Mod 8TB
Like the line (//document.onKeyDown=isBack(event);) . 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.
Jul 5 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by dennis | last post: by
1 post views Thread by Matthew Louden | last post: by
1 post views Thread by AssanKhan Ismail | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.