thatsIT
thatsIT

Reputation: 2175

jQuery which event differs between firefox developer browser and other browsers

I noticed that "-" and "+" (not those on the numpad) gives me different values. I compared it here: http://api.jquery.com/event.which/

http://www.words4ublog.com/wp-content/uploads/2013/06/Keyboard-Layout.jpg

I got you a picture of a swedish keyboard layout. You'll find "+" next to "0" and "-" next to "right shift". Perhaps FF developer browser isn't designed to work with other regions?

Firefox developer: "+" equals 171 and "-" equals 173

Other browsers: "+" equals 187 and "-" equals 189

Is there any that can give me a reason to why this happens? For me it isn't any big deal, I'll it this issue be. Because I don't think that the final user uses FF developer. And if they do, they could still use the numpad.

Upvotes: 1

Views: 29

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074238

which isn't an event, it's a property on an event.

The keydown and keyup events use either keyCode or which (depending on browser, but jQuery handles it for you) to report the keycode of the key that was pressed. Keycodes vary somewhat from keyboard layout to keyboard layout and are in general a royal pain in the ###. Jan Wolter used to maintain this very useful page on the subject and even though he's stopped updating it, it's still really useful and informative.

The keypress event uses keyCode/charCode/which to report the character that was pressed. This is after the translation of the keycode into a character and is much more consistent than the keycodes from keydown/keyup events.

In general, keypress is the more useful event; use keydown only when you have to detect a key that won't result in a keypress (like arrows).

Upvotes: 2

Related Questions