Reputation: 1871
How can I detect an onclick or ontouchend event inside a UIWebView? Or is this even possible?
Thank you.
Upvotes: 2
Views: 2095
Reputation: 1973
try this way :
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:webView];
if(CGRectContainsPoint([webView frame], currentLocation)){
//perfrom action
}
}
Upvotes: 0
Reputation: 9453
Subclass UIWebView and implement
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Do your code here
[super touchesBegan:touches withEvent:event];
}
EDIT
You can intercept the URL that was pressed using this UIWebViewDelegate method:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *link = url.absoluteString;
NSLog(@"Link pressed: %@", link);
return YES;
}
Upvotes: 1