Word on HTML document point, using UIWebView, DOM and Javascript
Posted
by leolobato
on Stack Overflow
See other posts from Stack Overflow
or by leolobato
Published on 2010-05-04T02:32:08Z
Indexed on
2010/05/04
10:58 UTC
Read the original article
Hit count: 298
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);
© Stack Overflow or respective owner