Currently I am taking this sample website and showing in my webview. The webpage is displaying correctly.
Now I am trying to figure out which data is selected once the user has tapped on the uiwebview.
For this I am able to get the CGPoint for the tap by using UITapGestureRecognizer
.
-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint touchPoint = [gestureRecognizer locationInView:myWebView];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];
NSString * tagName = [myWebView stringByEvaluatingJavaScriptFromString:js];
NSLog(@"Selected Name: %@",tagName);
}
// In log it is displaying [object SVGPathElement]
I want to get the exact data once user selects the vertical bar in first graph (E.g. 1994/1995/1996).
How to do this?
You don't specify what is that is not working for you... anyway, a couple of suggestions:
try with the following js in your tap handler:
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
when creating your tap gesture handler, specify a delegate for it (it can be your controller):
tap1.delegate = self;
in your controller (or web view delegate), define the following delegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer*)otherGestureRecognizer {
return YES;
}
if you are using iOS 5, have a look at this article about a glitch in elementFromPoint
.
By doing like this, I am able to get the exact HTML value for the selected object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With