views:

49

answers:

1

How would I go about detecting which HTML element was tapped inside a UIWebView?

It seems a bit hacky, but right now the only way I can think of would be to evaluate JavaScript and use JS to traverse the DOM. Any help with this direction would be appreciated, too.

A: 

You could add a javascript function that takes a single argument, an id or whatever you prefer, and then add an onclick to all elements you are interested in that calls this function:

<html>
<head>
<title>Click test</title>
<script type="text/javascript">
function myClickHandler(elm)
{
    alert('' + elm + ' element clicked');
}
</script>
</head>
<body>
<h1 onclick="myClickHandler('first');">First element</h1>
<h1 onclick="myClickHandler('second');">Second element</h1>
</body>
</html>

Edit: Ooh - you re not looking for a html/javascript solution. sorry.

Mogens Beltoft