在Android的WebView preventing电子邮件和网址autolinking [英] Preventing autolinking of emails and URLs in an Android WebView
问题描述
我有一个的WebView
其中可能包含似乎越来越自动连接的数据。东西看起来像一个电子邮件地址成为可点击的,即使它现在在< A>
标签或有一个的onclick
属性。如何禁用这个自动链接?
I have a WebView
which may contain data that appears to be getting "auto linked". Something that looks like an email address is becoming clickable, even though it's now within an <a>
tag or has an onclick
attribute. How do I disable this auto-linking?
我已经看了thorugh的的WebView
文档,还有 WebSettings
文档,但似乎没有要看到任何提及这一行为。
I've looked thorugh the WebView
docs, as well as the WebSettings
docs, but didn't seem to see anything that mentions this behavior.
推荐答案
我知道这是一个有点晚了,但是为了将来的参考,这可能是将工作不管链接是创建或定义自动解决方案的&LT; A&GT;
- 标记。
I know this is a bit late, but for future reference, this might be a solution that will work regardless if the links are auto created or defined in the <a>
-tag.
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;
}
});
这篇关于在Android的WebView preventing电子邮件和网址autolinking的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!