Pages

Showing posts with label UIWebView. Show all posts
Showing posts with label UIWebView. Show all posts

Saturday, May 21, 2011

How to detect the link click in UIWebView


If App has an Web View and web view has some link and we want to identify the click event and open the link in  safari or open mail window, then follow as below code.

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
              
               //CAPTURE USER LINK-CLICK.
               if (navigationType == UIWebViewNavigationTypeLinkClicked) {
                        NSURL *URL = [request URL];   
                        if ([[URL scheme] isEqualToString:@"http"]) {
                                    [[UIApplication sharedApplication] openURL:URL];
                                    return NO;
                        }
                        else if ([[URL scheme] isEqualToString:@"mailto"])  {
                                    [[UIApplication sharedApplication] openURL:URL];
                                    return NO;
                        }
               }        
               return YES;  
}