How to implement event handling in uiwebview?
I have taken a webview to show some HTML content in iPhone. Now I want to put some action on user events on the phone. I want to trac开发者_运维百科e the tap event done on the screen by the user on that web view. For this I have added a method -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { in my code. But the problem is when I click outside the webview it works perfectly. Bt when I tap on the web view, it does not respond. So, please tell me what should I do to acheive tap event trace on that particular web view. Help me out.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([[url lastPathComponent] isEqual:@"testmessage"]) {
NSLog(@"Nya");
return NO;
}
return YES;
}
HTML
<a href='testmessage'>Test</a>
or
<script>
function callObjc(){
document.location = 'testmessage';
}
</script>
<a onclick='callObjc();'>Test</a>
精彩评论