Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebview set text on current textfield

Is there a way to set the text on the current textfield on a UIWebview?

I don't need to retrieve the text. I don't need to determine what text field currently has focus.

Basically the user will scan a barcode (with the linea-pro) and if there is a textfield selected in the uiwebview I just want to set the text to the retrieved barcode

like image 683
Hackmodford Avatar asked Aug 07 '26 02:08

Hackmodford


1 Answers

You can exec JavaScript function that can set value to text field. Something like this

NSString *text = @"Text field text";
NSString *javaScript = [NSString stringWithFormat:@"var textField = document.activeElement;"
                                                   "textField.value = '%@';"
                                                   "document.activeElement.form.submit();", text];
[webView stringByEvaluatingJavaScriptFromString:javaScript];
like image 149
Sergey Kuryanov Avatar answered Aug 09 '26 14:08

Sergey Kuryanov