I have a webview with an HTML webpage downloaded from the server, and I fill in the dynamic data and add lines of information to this webpage. I used the following code on this webpage to enable javascript:
class JSClass { Context jsContext; JSClass(Context c){ jsContext = c; } public void getHTMLContent(String info) { Log.i(TAG, "Info: "+info); } } WebView webview = (WebView) findViewById(R.id.webView); webview.loadDataWithBaseURL("", htmlcontent, "text/html", "utf-8", ""); webview.getSettings().setJavaScriptEnabled(true); webview.setWebChromeClient(new WebChromeClient()); webview.addJavascriptInterface(new JSClass(this), "Android"); webview.loadUrl("javascript:"+ "var rows = document.getElementsByClassName('info');"+ "if(rows !== null){"+ "for(var i=0;i<rows.length;i++){"+ "rows[i].onclick = function(){"+ "var workId = 0;"+ "workId = parseInt(this.cells[0].innerHTML);"+ "window.Android.getHTMLContent(workId);"+ "}}}" );
when I click on any line, I intend to download images from the server depending on the data in the line. It works fine on the first click, but the second time I click, the application closes without any errors. I do not understand the reason. Please help. thanks in advance
source share