1. 程式人生 > >iOS WKWebView 禁止長按(超連結、圖片、文字...)彈出效果

iOS 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);
    }
}

方法二:

//WKWebview 禁止長按(超連結、圖片、文字...)彈出效果
    [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
    [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];


君凱商聯網-iOS-字唐名僧