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?
What you need to do is create a new input field, append it to the body, focus it and the hide it using display:none
. You will need to enclose these inside some setTimeouts unfortunately to make this work.
var field = document.createElement('input');
field.setAttribute('type', 'text');
document.body.appendChild(field);
setTimeout(function() {
field.focus();
setTimeout(function() {
field.setAttribute('style', 'display:none;');
}, 50);
}, 50);