471,616 Members | 1,025 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

window.onkeydown but not for a specific div or form

I have set window.onkeydown which works fine.
One of my shortcut keys is "n", so a user can not type "n" in forms.
How do I solve that?

Thanks,
Jacob
Jul 23 '05 #1
5 4281
Jacob Friis Larsen wrote:
I have set window.onkeydown which works fine.
One of my shortcut keys is "n", so a user can not type "n" in forms.
How do I solve that?

Thanks,
Jacob


<script type="text/javascript">

document.onkeydown = function(e)
{
var tgt = null;
if ((e = e || window.event)
&& (tgt = e.target || e.srcElement)
&& tgt.type
&& /text/.test(tgt.type))
return true;
else
{

//stuff here

}
}

</script>

Jul 23 '05 #2
Could someone please explain what this does?

Thanks,
Jacob

Jul 23 '05 #3
Jacob Friis Larsen wrote:
Could someone please explain what this does?

Thanks,
Jacob
Someone here. Best I could do, based on this detailed description:
I have set window.onkeydown which works fine.


document.onkeydown = function(e)
{
var tgt = null;
if ((e = e || window.event) //get event object
&& (tgt = e.target || e.srcElement) //get trigger element
&& tgt.type //has 'type' property?
&& /text/.test(tgt.type)) //'text' or 'textarea'?
return true; //end processing
else
{

// shortcut code

}
}

</script>

Jul 23 '05 #4
Thanks alot RobB :)
Kind regards Jacob

Jul 23 '05 #5
What if a user press ' to search for a link in Firefox?
I see this as a problem for gmail too.
Can that be fixed?

Thanks, Jacob

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Brad Jones | last post: by
5 posts views Thread by Russell Campbell | last post: by
32 posts views Thread by Eli | last post: by
5 posts views Thread by Dave Henson | last post: by
3 posts views Thread by news.microsoft.com | last post: by
8 posts views Thread by Someone | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.