JavaScript Keypress Event Not Raised on Android Browser

JavaScript keypress event not raised on Android browser

Use the keyup event:

// JavaScript:
var counter = 0;
document.querySelector('input').addEventListener('keyup', function () {
document.querySelector('div').textContent = `key up ${++counter}`;
});

// jQuery:
var counter = 0;
$('input').on('keyup', function () {
$('div').text('key up ' + ++counter);
});

keyup, keydown and keypress events not working on mobile

keydown should work, but you could use the input event which seems to have undesired effects on Android mobile...

To get the code of the pressed key use the jQuery's normalized Event.which

Android Chrome tested:

Using input Event (e.which gives always 0 so it seems like a bug on android devices)

jQuery(function($) { // DOM ready and $ alias secured
$('#buscar-producto').on('input', function(e){ var key = e.which || this.value.substr(-1).charCodeAt(0); alert( key ) });
});
<input type="text" id="buscar-producto" placeholder="Buscar...">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>

android enter key event not working in jquery

Reedit:

$('#search').on('keyup',function(e) { 
if (e.keyCode == 13) {
$('#search').blur();
}
});

Android Phone - Input field retaining every keypress and appending on replace

I was able to solve the same using following script
(Ref : JavaScript keypress event not raised on Android browser)

$(window).load(function(){
$('.alpha').on('keyup input', function (event) {

if(event.type == 'input') {
var bufferValue = $(this).val().replace(/[^A-Za-z]/g,'');
$(this).val(bufferValue);
}

});
});

JavaScript keypress event not raised on Android browser

Use the keyup event:

// JavaScript:
var counter = 0;
document.querySelector('input').addEventListener('keyup', function () {
document.querySelector('div').textContent = `key up ${++counter}`;
});

// jQuery:
var counter = 0;
$('input').on('keyup', function () {
$('div').text('key up ' + ++counter);
});


Related Topics



Leave a reply



Submit