
Untitled
By: a guest on
Jun 14th, 2012 | syntax:
None | size: 1.05 KB | hits: 20 | expires: Never
detect javascript button press in webview?
<input id="testBtn" name="testBtn" type="button" value="Test Button"
class="button" onclick="test.run(this.id,'onclick');return false;"
onkeydown="test.run(this.id,'onkeydown');return false;" title="Test Button">
final class jocJavaScriptInterface {
jocJavaScriptInterface() {
}
String myEvent;
public void run(int id,String event) { //run method defined into your html.
this.myEvent = event;
mHandler.post(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(),myEvent + " my ButtoN!", Toast.LENGTH_LONG).show();
}
});
}
}
WebContent.addJavascriptInterface(new jocJavaScriptInterface(), "test");
WebContent.loadUrl("http://www.foo.com/Androidtest.html"); //load your Page with the button...
WebSettings webSettings = WebContent.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);