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

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

作者: MichalWilson | 来源:发表于2018-09-18 10:46 被阅读75次

方法一:

//设置代理

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 WKWebView 禁止长按(超链接、图片、文本...)

      本文链接:https://www.haomeiwen.com/subject/ifwynftx.html