Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide keyboard on ios device when focus in input

I want hide virtual keyboard on ipad device when some plugin ( or other code) set focus to input element on html page using pure javascript( or jquery library)

like image 687
alx lark Avatar asked Nov 28 '22 15:11

alx lark


2 Answers

If you need a pure javascript solution, use this line :

document.activeElement.blur();

This line removes the focus on the active element and hiding the keyboard.


Reference

  • MDN document.activeElement
  • MDN HTMLElement.blur
like image 190
R3tep Avatar answered Dec 08 '22 20:12

R3tep


You would have to blur it again but the keyboard might flash.

$('input').on('focus', function() { $(this).blur(); });

Or, depending on if you have dynamically created input elements.

$('#wrapper').on('focus', 'input', function() { $(this).blur(); });
like image 23
ryan Avatar answered Dec 08 '22 21:12

ryan