Word on HTML document point, using UIWebView, DOM and Javascript
- by leolobato
Hey guys,
How can I figure out which word is at the point where the user tapped on a UIWebView?
I am able to detect the CGPoint for the tap (subclassing UIWindow like this), and I can actually get the DOM element on that point using javascript.
But I know very little of javascript and DOM to figure out how can I actually get which word the user tapped on.
Is that possible? Here's what I have right now:
int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", point.x, point.y+scrollPosition];
NSString *value = [webView stringByEvaluatingJavaScriptFromString:js];
NSLog(@"element: %@", value);