I need to detect the keycode for a custom search box on my website, but the keycode always returns as zero on Chrome for Android (except for backspace, which returns 8). Has anyone else experienced this, and how did you get around it? Our website works on all mobile browsers except Chrome for Android because we can't detect a non-zero keycode or charcode.
I'm running Chrome 27.0.1453.90 on Android 4.1.2 Jelly Bean. The problem can be duplicated with something as simple as:alert(event.keyCode);
KeyCode was deprecated because in practice it was “inconsistent across platforms and even the same implementation on different operating systems or using different localizations.” The new recommendation is to use key or code .
According to the website, key-code for . is 190.
below solution also work for me. might be useful for others also.
var getKeyCode = function (str) { return str.charCodeAt(str.length - 1); } document.getElementById("a").onkeyup = function (e) { var kCd = e.keyCode || e.which; if (kCd == 0 || kCd == 229) { //for android chrome keycode fix kCd = getKeyCode(this.value); } alert(kCd) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With