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];