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
How to Add a CSS Class to a Raphael Object
Prevent Scroll Bounce for the Body Element, But Keep It for Child Elements in iOS
Permanently Change CSS Property with JavaScript/D3Js/Jquery
Pause/Resume CSS Animations When Switching Tabs
Why Do Arabic Characters Behave as Separate Characters When Styling Single Arabic Character
Why Blocking Event Loop Does Not Block CSS Animation
How to Combine Fixed Height Header with Flexible Page Layout
Why Do Developers Append a Query String in JavaScript Files' Stylesheet Links
Image Crossfade with JavaScript and CSS3 Transitions
Css3/Js Get Position of Element During Animation
Put Cursor at End of Text Input's Value
Css: Set Divs Horizontally in 2 Rows
Jquery Word for Word Fade in Effect