WKWebView - Detect tap without a link

Viewed 674

Is there a way to configure WKWebView in a way that internal gesture mechanism could catch any tap on the content not only on links? I want to detect a touch on an img tag where source="" attribute contains a link for the image.

I'm catching normal links taps with this method, it does not catch <img> tag

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    ...
}

And this is what I'm trying to detect

 <img src="http://example.com" alt="">

One way could be parsing the html content and wrapping every img tag with <a href=""/> tag but I don't want to mess too much with this content

If I add gesture recognizer to images it covers up whole view and links are impossible to click then because I'm going to image browser with delegate after this click, I'm detecting click on the link but it's fired up already after the delegate takes me to image browser.

To sum up. I've got hooked up gesture recognizer to WebView and I'm using decidePolicyForNavigationAction for opening links. Gesture recognizer fires up on every click wherever it happens in the view, and decidePolicyForNavigationAction fires up only on link click. Can I somehow negate the gesture if I'm clicking the link? Right now it's firing two listeners at once but gesture is faster so it covers actions from opening the link

0 Answers
Related