Friday, October 31, 2008

IE and Firefox: onKeyPress

MS Internet Explorer and Firefox handle the keyPress event differently - MS IE only fires the event for non-special characters while Firefox fires the event for all key presses.

IE returns the key that caused the event in event.keyCode. Firefox uses event.which and event.keyCode; if you want to handle special keys, you can read the value from event.keyCode (event.which is 0 for *most* special keys) or you can stick with event.which for the most part.

No comments: