iOS WKWebView 禁止长按(超链接、图片、文本...)

2018-09-18  本文已影响75人  MichalWilson

方法一:

//设置代理

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

上一篇 下一篇

猜你喜欢

热点阅读