Search code examples
iphoneobjective-ciosuiwebviewuiwebviewdelegate

Hyperlink click method in UIWebview


I have one UIWebView in my iphone app and I have to detect on click method whenever user will click on any hyperlink. I want to call one method when user will click on hyper link I know about the method

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

but it will be detected whenever any link will be loaded whether user has clicked or not on hyperlink but I want to call method only when user will click on any method. Please get me out of this issue. -Thanks in advance.


Solution

  • You can check the UIWebViewNavigationType.

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        if (navigationType == UIWebViewNavigationTypeLinkClicked) {
            NSLog("User tapped a link.");
        }
    }
    

    See UIWebView Class Reference for more information.