单击iOS UIWebView中的html链接不执行任何操作

单击iOS UIWebView中的html链接不执行任何操作,ios,hyperlink,uiwebview,uiwebviewdelegate,Ios,Hyperlink,Uiwebview,Uiwebviewdelegate,我有UIWebView,它使用loadHTMLString从核心数据加载html内容。如果我在html内容中有html链接(例如,),并单击此链接,则它不会执行任何操作。绝对没有什么事发生 我试图实现委托方法shouldStartLoadWithRequest,当我打印request.URL的内容时,它返回about:blank 我试图在我的UIWebView webView.userInteractionEnabled = true webView.dataDetectorTypes = UI

我有
UIWebView
,它使用
loadHTMLString
从核心数据加载html内容。如果我在html内容中有html链接(例如,
),并单击此链接,则它不会执行任何操作。绝对没有什么事发生

我试图实现委托方法
shouldStartLoadWithRequest
,当我打印
request.URL的内容时,它返回
about:blank

我试图在我的
UIWebView

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

有人知道可能是什么问题吗???

请尝试以下代码。 实现UIWebview委托方法

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if(navigationType==UIWebViewNavigationTypeLinkClicked)
    {
        [[UIApplication sharedApplication]openURL:request.URL];
        return NO;
    }
    return YES;
}

请尝试使用以下代码。 实现UIWebview委托方法

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if(navigationType==UIWebViewNavigationTypeLinkClicked)
    {
        [[UIApplication sharedApplication]openURL:request.URL];
        return NO;
    }
    return YES;
}

在Swift 4.2上

您可以尝试以下代码,必须是implementUIWebViewDelegate

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
}

在Swift 4.2上

您可以尝试以下代码,必须是implementUIWebViewDelegate

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
}

您是否使用以下方法获取url
[webView stringByEvaluatingJavaScriptFromString:@“document.getElementById('xyz').href]”谢谢你的回答。我现在试过了,它返回“
http://www.google.com/
“这应该是可以的。@marysmech:发布一个与您合作的答案…您是否使用以下方法获得url
[webView stringByEvaluatingJavaScriptFromString:@”document.getElementById('xyz').href]谢谢你的回答。我现在试过了,它返回“
http://www.google.com/
“这应该没问题。@marysmech:发布一个答案,无论你做了什么。。。