I would like to hide the Android virtual keyboard in JavaScript. Someone suggested doing this:
$('#input').focus(function() {
this.blur();
});
But this doesn't work if the keyboard is already visible. Is this something that can be done?
I found a simpler solution that requires neither adding element nor a special class. found it there: http://www.sencha.com/forum/archive/index.php/t-141560.html
And converted the code to jquery :
function hideKeyboard(element) {
element.attr('readonly', 'readonly'); // Force keyboard to hide on input field.
element.attr('disabled', 'true'); // Force keyboard to hide on textarea field.
setTimeout(function() {
element.blur(); //actually close the keyboard
// Remove readonly attribute after keyboard is hidden.
element.removeAttr('readonly');
element.removeAttr('disabled');
}, 100);
}
You call the function by passing it the input from which the keyboard was opened, or just passing $('input') should also work.