Reputation: 28519
Given an HTML document like this, hosted inside a WebView, how do I catch click events so they can be handled by my code, rather than the WebView?
<div onclick="location.href='http://www.blah.com/blah';">
The HTML is provided from another source, so it is desirable to to handle click events on the HTML without altering the HTML document as I cannot make assumptions about its structure.
Upvotes: 3
Views: 6782
Reputation: 1012
You need to add a JavaScript interface (addJavascriptInterface
) to your Webview and you can then call Java objects from your javascript code.
Check this:
You then create a function that is called on click, calling your registered Java object.
Upvotes: 1
Reputation: 2679
You can use the addJavaScriptInterfaceMethod()
in WebView.
Also more information can be found here in the Binding JavaScript code to Android code section.
Upvotes: 4