I\'m using a WKWebView to load a website and everything is working fine. However, I do not have access to the keyboard properties the same way I do with a textfield. Can someone
I have an HTML auth page that I display in WKWebView. The autocorrect / suggestion bar appears above the keyboard for the username field. Since I don't control the HTML, I used the following Swift 3 code and javascript to add the autocorrect attribute as mentioned above:
var webView: WKWebView!
override func loadView() {
let autocorrectJavaScript = "var inputTextElement = document.getElementById('username');"
+ " if (inputTextElement != null) {"
+ " var autocorrectAttribute = document.createAttribute('autocorrect');"
+ " autocorrectAttribute.value = 'off';"
+ " inputTextElement.setAttributeNode(autocorrectAttribute);"
+ " }"
let userScript = WKUserScript(source: autocorrectJavaScript, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
let webConfiguration = WKWebViewConfiguration()
webConfiguration.userContentController.addUserScript(userScript)
webView = WKWebView(frame: .zero, configuration: webConfiguration)
view = webView
}
Note: The bar above the keyboard still remains, with other options, just not the suggestions.