简体   繁体   中英

WebView does not load javascript codes

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.

在此处输入图片说明

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");

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.

I have solved the problem finally. The htmlData contains unexpected characters which are \\n and \ 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 -->", "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM