- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
// 1.拦截请求
NSString *urlString = [navigationAction.request.URL absoluteString];
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
//跳转别的应用如系统浏览器
// 对于跨域,需要手动跳转
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
// 不允许web内跳转
decisionHandler(WKNavigationActionPolicyCancel);
} else {
//应用的web内跳转
decisionHandler (WKNavigationActionPolicyAllow);
}
return ;//不添加会崩溃
}
iOS WKWebView 拦截超链接
最新推荐文章于 2024-09-14 07:44:44 发布