Get selected items programmatically from uiwebview?

I am currently taking this sample website and showing in my web review. The web page is displayed correctly.

Now I'm trying to figure out what data is selected when the user clicked on uiwebview.

For this, I can get CGPoint for a tap 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 accurate data as soon as the user selects a vertical bar in the first graph (for example, 1994/1995/1996).

How to do it?

+5
source share
3 answers

You do not indicate that this does not work for you ... anyway, a few suggestions:

  • try to execute the following js in the tap handler:

    NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
    
  • , ( ):

    tap1.delegate = self;
    
  • ( -), :

    - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:    (UIGestureRecognizer*)otherGestureRecognizer {
        return YES;
    }
    
  • iOS 5, elementFromPoint.

, HTML .

+2

DOM, touchstart JavaScript, , event.target, , . , JS, Objective-c. JS - UIWebView, , , !

0

UIWebView, HTTP- AJAX, UIWebViewDelegate,

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

.

, , , .

0

All Articles