My iOS app uses a WKWebView
with contenteditable = true
on a specific div
. I'd like to have code to make the keyboard show up for the web view, so the user can just start typing. Things I've tried that have had no effect:
becomeFirstResponder
(a long shot, because the web view wouldn't know what div
to use). div
to focus()
. (This works in other browsers, but sadly not in WKWebView
) TouchEvent
and dispatchEvent()
in the hope of making it seem that the user had tapped on the div
. In the third case I also used addEventListener()
to observe the simulated touches and compare them to real touch events from tapping the screen. It looks like the key difference is that the event's isTrusted
value is false for the simulated touches.
I get that it's a potential security issue to let apps simulate touch events, but I didn't have any other ideas. I'm trying to get the keyboard to appear, what the user types is up to them and not something I want to mess with. Basically I want the same thing as calling becomeFirstResponder()
on a UITextView
.
This is very similar to a WebKit issue 142757 but I haven't figured out how to use the suggested workaround linked from there.
Clarification: I can set up and use an editable web view, but the keyboard doesn't appear until I tap on the web view. I'm trying to make the keyboard appear automatically, without requiring a tap to initiate editing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.