Search code examples
htmliosiphoneipad

Detect element I click in UIWebView


How I can detect element I click in UIWebView. I have simple html, but I want differ elements, so I want get for example "alt" from the element I click.

In points:

  1. User click one of images loaded in WebView.
  2. It calls function that has info which about clicked element.

Is it possible?


Solution

  • You should add some bindings between your webview and your Objective-C. You can do this using javascript.

    You pretty much inject javascript into the webview so you will get a event when some HTML element is touched. Then your javascript will communicate to Objective C, to trigger some action.

    This is technique is described pretty well here: http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/