So I\'ve seen a lot of threads about the iOS issue with focusing on an input/textarea element. (See here and here) It seems that iOS will not let you manually focus on one o
On your UIWebView
, set keyboardDisplayRequiresUserAction
to NO
.
This seems to happen on iOS12 only. .Focus works fine in iOS11&13
WKWebView version of keyboardDisplayRequiresUserAction = NO
from thedyrt/cordova-plugin-wkwebview-engine:
#import <objc/runtime.h>
- (void) viewDidLoad {
...
SEL sel = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
Class WKContentView = NSClassFromString(@"WKContentView");
Method method = class_getInstanceMethod(WKContentView, sel);
IMP originalImp = method_getImplementation(method);
IMP imp = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
((void (*)(id, SEL, void*, BOOL, BOOL, id))originalImp)(me, sel, arg0, TRUE, arg2, arg3);
});
method_setImplementation(method, imp);
}
I have also harassed same this like issue.
my issue solved by simple one css property that is -webkit-user-select:none
I removed this and all works fine.
try out this.
I used iPad Air [iOS 7.0.4], iPad Mini [iOS 7.1] and jQuery [1.11.3] for my test.
The .focus event worked perfectly for me both in input and textarea fields.
I am pasting the code below with which I tested. Please let me know if I am missing anything.
Is it for some previous version of iOS / jQuery ?
My HTML,
<body>
<!--<input id="in" type="text"/>-->
<textarea id="in"></textarea>
<button id="btn">Add Focus</button>
</body>
My query,
$('#btn').click(function(){
$('#in').focus();
})