javascript - Why are arrow keys, tab, etc not received by input field's onkeypress handler in some browsers? -


I am creating specific text input fields to enter and edit time. One of the components of functionality needs different ways of focusing on different components of time (hours, minutes, seconds), which I represent through text selection. Is possible with direct selection mouse and it is working great. The second feature is keyboard navigation.

Most of this functionality depends on the fact that I am capable of handling keyboard events, suppressing default behavior and instead of a particular action option

in Firefox , I have to work this well to make users use the left / right arrow key or tab / change tab to move between parts of the timeline (and when they reach the end, the next tab Will leave the passenger area and will normally focus on the next element).

In Internet Explorer 7 (possibly other?) Arrow keys and tabs are not received by the keyboard handler if the arrow key is pressed, the text selection is lost and the cursor moves through one of several The effects of making the areas disappear and the result is broken into control. The tab also leaves the handler and immediately flips on the next focusable element.

Is there any trick to block these keys?

You need to use onkeydown for the non-character key. ONKeypress handles only one string returning keys in IE.

To quote MSDN documents in particular:

As Microsoft Internet Explorer 4.0, the onkeypress event can be fire and canceled

  • Letters: 0 - 9 @ # $% ^ & Amp; * () _ - + = & lt; [] {},. /? \ | '`" ~
  • System: ESC, Spacebar, Enter

  • Comments

    Popular posts from this blog

    c++ - Linux and clipboard -

    What is expire header and how to achive them in ASP.NET and PHP? -

    sql server - How can I determine which of my SQL 2005 statistics are unused? -