I know it exists a lot of questions about that but i don't understand why my following code does not work anymore
Here is my code :
private void init() {
webview.setWebViewClient(new FormWebViewClient());
webview.postUrl(url, EncodingUtils.getBytes(data, "BASE64"));
}
private class FormWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
// progressBar.setVisibility(View.VISIBLE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
LOGD(TAG, "Url : " + url);
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:" +"document.getElementsByClassName('my_class_name')[0].value = '" + myValue + "';" +
}
}
My original webview is overrided and it displays only myValue
in the page instead of plenty of informations.
If anybody knows why i have this behavior ...
Thx
EDIT :
and the part of html
<input type="text" size="20" maxlength="19" autocomplete="off" name="CARD_NUMBER" id="CARD_NUMBER" class="my_class_name" value="">
Add a new method to inject javascript file. Call both methods: injectCSS() and injectJS() after page finishes loading. webView. setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { injectCSS(); injectJS(); super.
Use injectJavaScript as per (Guide > Communicating between JS and Native > The injectJavaScript method)[https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#the-injectjavascript-method"]. In your case, that would be something like this. webview. injectJavaScript(jsCode)
Enable JavaScript JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.
Finally, I've found the answer :
I have to add void(0);
at the end of JavaScript instruction like this :
view.loadUrl("javascript:" +"document.getElementsByClassName('my_class_name')[0].value = '" + myValue + "';void(0);")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With