代码之家  ›  专栏  ›  技术社区  ›  Alex Wayne

在Android WebView中防止电子邮件和url的自动链接

  •  4
  • Alex Wayne  · 技术社区  · 14 年前

    WebView 其中可能包含看起来正在“自动链接”的数据。一些看起来像电子邮件地址的内容正在变得可点击,即使它现在位于 <a> onclick 属性。如何禁用此自动链接?

    我已经看过了 网络视图 文档,以及 WebSettings 医生,但似乎没有看到任何提到这种行为的东西。

    alt text http://beautifulpixel.com/assets/5554_Fast-20100706-110228.png

    5 回复  |  直到 14 年前
        1
  •  6
  •   Paaske    13 年前

    我知道这有点晚了,但为了将来参考,这可能是一个解决方案,无论链接是在 <a> -标签。

    myWebView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // return true; // will disable all links
    
            // disable phone and email links
            if(url.startsWith("mailto") || url.startsWith("tel")) {
                return true;
            }
    
            // leave the decision to the webview
            return false;
        }
    });
    
        2
  •  2
  •   Michael come lately PhiLho    5 年前

    待办事项 全部的

    <meta name="format-detection" content="email=no" />
    

    您还可以禁用物理地址和电话检测:

    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="address=no" />
    

    不过,在我自己的申请中,我需要 PhD's solution 以防止只有一封电子邮件被链接。

        3
  •  1
  •   PhD    13 年前

    我也有同样的问题,试过这个:

    <a onClick=\"return false;\">jorgesys@elnorte.com</a>
    

    它没有起作用。

    然后尝试:

    <a href='javascript:void(0);'>800-644-9737</a>
    

    它成功了

        4
  •  0
  •   Jorgesys    14 年前

    嗨,Squeagky为什么你想从webview中消除这种功能性,但是有一个棘手的方法是 onClick="return false;" 在包含电子邮件或URL的锚标记中。

    <a onClick=\"return false;\">jorgesys@elnorte.com</a>
    
        5
  •  -1
  •   Community CDub    7 年前

    你可以做相反的事 Is there any way to have WebView auto-link URLs and phone numbers in Android? 并创建一个javascript链接剥离器(而不是这里提议的链接注入器)。

    不知道还有什么能解决这个问题。