Manually triggering the iPhone/iPad/iPod keyboard from JavaScript

后端 未结 7 1174
[愿得一人]
[愿得一人] 2020-11-28 12:34

I am developing an HTML code editor using simple DIV\'s and capturing events. When I use this on the iPad the keyboard never pops up since i\'m not technically in an editab

7条回答
  •  一向
    一向 (楼主)
    2020-11-28 13:03

    Proxy input trick

    I figured out another dirty workaround, but works well. The trick is based on the fact, that if the keyboard is already open, changing the focus will not close the keyboard.

    1. Add a small "proxy invisible input" in top left of the page with position fixed (the fixed position prevents the flicker, also make sure that the field has font-size bigger than 16px to prevent iOS page zoom on focus)
    2. On clicking the button, just .focus() on this invisible field. The keyboard will open...
    3. Show or render your other input fields
    4. Now with the keyboard open just .focus() on the desired input. You can use small setTimeout delay, for example 500ms if needed

提交回复
热议问题