window.onkeydown but not for a specific div or form

J

Jacob Friis Larsen

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
 
R

RobB

Jacob said:
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>
 
R

RobB

Jacob said:
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>
 
J

Jacob Friis Larsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top