Search code examples
javascriptgoogle-chromedommobilekeyboard

Android chrome: avoid keyboard to hide when icon is pressed


Chrome's default behavious is to hide the keyboard, when this one is open/shown and I click in any part of the screen. I want to achieve to prevent it from hidding if I click in a specific DOM element. Is that possible using JS?

window.onclick = function(event) {
  var sendMsgBtn = document.getElementById("send-msg-icon");
  if (event.target == sendMsgBtn) {
    //what to do here
  }
}

Solution

  • If you focus on a <input> or <textarea> element (it may be hidden) and then you click on it, the keyboard will not hide

    window.onclick = function(event) {
       var sendMsgBtn = document.getElementById("send-msg-icon");
          if (event.target == sendMsgBtn) {
            var input1 = document.getElementById("input1");
            input1.focus();
            input1.click();
          }
      }