UIWebView 让用户触摸点击 link

UIWebView get user touch on tapping link

我想在用户单击 UIWebView 上的任何 link 时执行一些操作。我这样做是为了完成这项工作:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"request - %@", request.URL.absoluteString);
    [webView.window makeKeyAndVisible];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    if(isFirstTimeLoaded)
    {
        [self shoToolbar];
        [self updateButtons];
    }


    return YES;
}  

- (void)webViewDidFinishLoad:(UIWebView *)webView
{   
    isFirstTimeLoaded = YES;
}

这通常工作正常。但当 UIWebView 的第一次加载涉及加载页面时的多次重定向时,它不会。我想要的是仅当用户有意单击 link 时才触发此条件。不在 UIWebView 的 url 重定向上。

您必须检查导航类型

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

        if (navigationType==UIWebViewNavigationTypeLinkClicked) {
            // It was a link
        } else {
           // It wasn't a link
        }


        return YES;
    }