Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 876
kolek Avatar asked May 04 '12 00:05

kolek


1 Answers

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/

like image 78
bobbypage Avatar answered Sep 25 '22 05:09

bobbypage