2

Is there a way to programmatically interact with the contents of a WebView?

For example, how could my app:

  1. respond to an event (such as button clicked on a web page)

  2. iterate through all the INPUT elements in a page and retrieve their contents?

  3. Find all DIV elements with the class status and change their content?

Thanks!

Tony the Pony
  • 40,327
  • 71
  • 187
  • 281

1 Answers1

5

You can use Javascript to make a callback to Java for anything that Javascript can detect.

You can see a demo call JS to Java here: Android Calling JavaScript functions in WebView

Community
  • 1
  • 1
neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • Thanks! How do I set up such a callback? – Tony the Pony May 19 '11 at 10:13
  • Got it -- I can use a `WebChromeClient` as demonstrated here: http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java# – Tony the Pony May 19 '11 at 10:16
  • 2
    @TonythePony I think [this is the correct URL](https://code.google.com/p/apps-for-android/source/browse/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java) – Kapé Apr 25 '14 at 17:06