I was trying to detect the html button click of webview in java code.
My HTML Code:
<button id="fc_complete_order_button" class="fc_button" type="button" value="Complete Your Purchase" onclick="FC.checkout.validateAndSubmit()">Complete Your Purchase</button>
<div id="fc_complete_order_processing" style="display:none;">
<strong class="fc_error"></strong> <br>
<img src="//cdn.fox.com/static/v/1.1.0/images/ajax-loader.gif?ver=1" alt="Loading..." width="220" height="19">
</div>
My Java Code is:
final WebView browser = (WebView) findViewById(R.id.browser);
String html="";
try {
Document doc1 = Jsoup.connect(lastLoadedURL).get();
html=doc1.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new Object() {
@JavascriptInterface
public void validateAndSubmit() throws Exception {
Toast.makeText(MainActivity.this, "Login clicked", Toast.LENGTH_LONG).show();
}
}, "FC.checkout");
Can Anybody suggest where am doing wrong?