In Android, how can I set the value of an edit field in a WebView using Javascript

I understand how to set the value of an edit field in WebView and in a browser on a PC with Javascript.

First we find out the identifier of the edit field (text), then set the value using: On the PC:

document.getElementById('xxxxxxxx').value = 'test'

In Android:

mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').value = 'test'");

This script works on PC, but when I call the script in WebView.loadUrl, it just redefines my whole page to "check".

This is strange for me because the following Android code runs on this switch, but when it comes to the edit window, it just fails.

mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').checked = true");

Could you guys help me analyze what could be a possible reason? Thank you very much.

, javascript WebViewClient.onPageFinished( WebView, URL). , WebView . , .

+4
4

. - , javascript java-.

,

mWebView.loadUrl("javascript: [your javascript code]");

, . , , webview:

mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').value= 'test'");

, javascript :

mWebView.loadUrl("javascript: (function() {document.getElementById('xxxxxxxx').value= 'test';}) ();" );

. , .

+17

, . , , :

mWebView.loadUrl("javascript: myFunction('test')");

, @JavascriptInterface

0

:

String ABC="50";

myWebView.loadUrl("javascript: (function(){document.getElementById('countLiveSteps').value ='" + ABC + "';})();");
0

setText() TextView, :

TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

"message" - String, textView, , . https://developer.android.com/training/basics/firstapp/starting-activity.html

EditText setText()

-4
source

Source: https://habr.com/ru/post/1548561/


All Articles