I am trying to upload data to android webview using
webview.loadDataWithBaseURL("", htmlcontent, "text/html", null, "");
The method returns an htmlContent from a StringBuilder that fills the html data.
I turned on javascript and installed webChromeClient as follows
webview.getSettings().setJavaScriptEnabled(true); webview.setWebChromeClient(new WebChromeClient()); webview.addJavascriptInterface(new JSClass(), "Android");
my javascript interface:
class JSClass { public void getHTMLContent(String html) { Log.i(Global.TAG, "HTMLContentReceived: "+html); } }
and my javascript on the html page:
<script type="text/javascript"> var ele = document.getElementsByClassName('test'); for(var i=0;i<ele.length;i++){ ele[i].onclick = function(){ window.Android.getHTMLContent(this.innerHTML); } } </script>
but somehow javascript does not return any value. It works fine with loadData (url), where url is a simple web page in the resource folder
Please help Thanks in advance
source share