WKWebView 禁止跳转链接

//设置代理
self.wkWebView.navigationDelegate = self;


#pragma mark - wkWebViewDelegate
//禁止链接跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    NSLog(@"navigationAction = %@, request = %@",navigationAction,navigationAction.request.URL);

    if ([navigationAction.request.URL.scheme containsString:@"http"]) {
        decisionHandler(WKNavigationActionPolicyCancel);
    } else {
        decisionHandler(WKNavigationActionPolicyAllow);
    }
}

你可能感兴趣的:(iOS)