0

I am trying to open an html page on webview using loadData method with the string parameter which has the html + javascript code.

But the result is not what I wanted. As I understand it did not load javascript parts even though I enabled javascript.

If it is not possible with webview, is there another way to show my page on android phone which supports javascript codes? Thanks in advance.

enter image description here

This is my related code:

 WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);
 WebSettings webSettings = mWebView.getSettings();
 webSettings.setJavaScriptEnabled(true);
 mWebView.loadData(htmlData, "text/html; charset=utf-8", "UTF-8");
Hilal
  • 902
  • 2
  • 22
  • 47

2 Answers2

0

Looks like something wrong with your form. Action cant redirect to external site. Try to get all values from form manually and use something like Ajax to send post request.

Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
  • But I do not want to post the form *for now*, I just want to show it. When user fill the form he will send the form. This picture is when I show it using webview. – Hilal Jun 24 '16 at 08:11
  • Sorry I understand now, But how to get all values I have only string data with html codes. – Hilal Jun 24 '16 at 08:26
  • Ok, I think I should use JSInterface, but there is no good source about that how to implement that JSInterface to get all values, do you have any idea ? – Hilal Jun 24 '16 at 08:33
  • Get values in js function just like you do it always - typical js document.getElementsByName() and then send it by js, or execute this js function in Java. – Andrey Danilov Jun 24 '16 at 09:06
  • Also if you want to get value from js to java you can see this topic http://stackoverflow.com/questions/25074903/android-how-i-can-call-javascript-function-and-getting-the-retur-value-from-ja – Andrey Danilov Jun 24 '16 at 09:12
  • So should I use [something like this](http://stackoverflow.com/a/28880776/5528870) I should create inject.js Then get all values and send. And there would be some **buildInjection()** method ? I am a little bit confused. I will really appreciate if you can clear it for me? – Hilal Jun 24 '16 at 09:46
0

I have solved the problem finally. The htmlData contains unexpected characters which are \n and \u0000 and <!-- etc. I replaced my string by deleting them and now it works. Thanks for all.

htmlData = htmlData.replace("\\n", "");
htmlData = htmlData.replace("\\t", "");
htmlData = htmlData.replace("\\u0000", "");
htmlData = htmlData.replace("\\", "");
htmlData = htmlData.replace("\"\"\"", "");
htmlData = htmlData.replace("<!--function", "function");
htmlData = htmlData.replace("<!-- about:blank -->", "");
Hilal
  • 902
  • 2
  • 22
  • 47