0

I have UIWebView that load html content using loadHTMLString from core data. If i have html link (eg. <a href="http://www.google.com">google</a>) in html content and click this link it does nothing. Absolutely nothing happen.

I tried to implement delegate method shouldStartLoadWithRequest and when I print content of request.URL it returns about:blank.

I tried to to set in my UIWebView

webView.userInteractionEnabled = true
webView.dataDetectorTypes = UIDataDetectorTypes.All

Do anybody knows what could be wrong??

marysmech
  • 183
  • 1
  • 3
  • 10

2 Answers2

2

Please try with the following code. Implement the UIWebview Delegate method

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if(navigationType==UIWebViewNavigationTypeLinkClicked)
    {
        [[UIApplication sharedApplication]openURL:request.URL];
        return NO;
    }
    return YES;
}
IKKA
  • 6,297
  • 7
  • 50
  • 88
2

On Swift 4.2

You can try with the following code, must be implement UIWebViewDelegate

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {
    if navigationType == .linkClicked {
        if let url = request.url {
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            } else {
                UIApplication.shared.openURL(url)
            }
        }
        return false
    }
    return true
}
Ridho Octanio
  • 543
  • 5
  • 14