简体   繁体   English

如何拦截长按UIWebView中的链接?

[英]How to intercept long press on links in UIWebView?

I want to provide my own action sheet or popover, don't want default system one. 我想提供自己的操作表或弹出窗口,不希望默认系统一。

Please notice that: 请注意:

  1. I'm asking about long press not click . 我问长按点击
  2. I need to know the URL of the link that is being long pressed. 我需要知道长按的链接的URL。

In order to provide your own action sheet or popover, first you need to disable the default contextual menu. 为了提供您自己的操作表或弹出窗口,首先需要禁用默认的上下文菜单。 You can do it with javascript by using the following code, inside webViewDidFinishLoad 您可以使用以下代码在webViewDidFinishLoad使用javascript来完成此webViewDidFinishLoad

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];

Once you disable the default behavior you can create your own custom action sheet/popover. 禁用默认行为后,您可以创建自己的自定义操作表/弹出窗口。

One possible approach is described in the following link: 以下链接描述了一种可能的方法:

Customize the contextual menu of UIWebView 自定义UIWebView的上下文菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM