Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autocomplete in UIWebView/WKWebview

Im working on a simple app that acts as a webview. I need to disable auto complete and several other keyboard functions on anything loaded in the webview. I know how to disable autocomplete per UITextInput in a normal view controller but I don't know weather you can disable autocomplete globally on a webview?

I looked at the documentation for UITextInputTraits Here but could not seem to make anything work.

A final resort would be to disable autocomplete in the HTML tags but that would require a lot of work on the back end.

Is there a way to disable autocomplete globally for the app?

Thanks in advance.

like image 861
Jerrion Avatar asked Jul 06 '15 15:07

Jerrion


2 Answers

I don't think there is a way to do this with iOS code. But, i might be wrong.

You can try running the below JS in the webview every time you load the web page

var textFields = document.getElementsByTagName('input');

if (textFields) {
    var i;
    for( i = 0; i < textFields.length; i++) {
        var txtField = textFields[i];
        if(txtField) {
            txtField.setAttribute('autocomplete','off');
            txtField.setAttribute('autocorrect','off');
            txtField.setAttribute('autocapitalize','off');
            txtField.setAttribute('spellcheck','false');
        }
    }
}

In my opinion, this should do the job without you having to do the changes in the server :)

Would be interested to know if this worked for you

like image 100
Subbu Avatar answered Oct 22 '22 15:10

Subbu


I have searched alot for this issue. If you want to totally disable it, then you have to use <textarea> instead of <div contenteditable="true"> and load it in UIWebview. Try the below code:

 <textarea id="content" spellcheck="false" autocorrect="off" autocomplete="off"></textarea>

By using this code, Predictive text and autocomplete both will get off.

like image 42
mohsin Avatar answered Oct 22 '22 14:10

mohsin