Yoh Suzuki Yoh Suzuki - 6 months ago 39
Android Question

How can I hide the Android keyboard using JavaScript?

I would like to hide the Android virtual keyboard in JavaScript. Someone suggested doing this (http://stackoverflow.com/questions/7045889/how-to-hide-keyboard-on-phonegap-android):

$('#input').focus(function() {

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');

setTimeout(function() {
    setTimeout(function() {
        field.setAttribute('style', 'display:none;');
    }, 50);
}, 50);