I would like to hide the Android virtual keyboard in JavaScript. Someone suggested doing this:
JavaScript
x
4
1
$('#input').focus(function() {
2
this.blur();
3
});
4
But this doesn’t work if the keyboard is already visible. Is this something that can be done?
Advertisement
Answer
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.
JavaScript
1
11
11
1
var field = document.createElement('input');
2
field.setAttribute('type', 'text');
3
document.body.appendChild(field);
4
5
setTimeout(function() {
6
field.focus();
7
setTimeout(function() {
8
field.setAttribute('style', 'display:none;');
9
}, 50);
10
}, 50);
11