开发者

Preventing autolinking of emails and URLs in an Android WebView

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 attri开发者_JS百科bute. How do I disable this auto-linking?

I've looked thorugh the WebView docs, as well as the WebSettings docs, but didn't seem to see anything that mentions this behavior.

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


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;
    }
});


To do all the email addresses, add a meta tag:

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

You can also disable physical address and telephone detection:

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

In my own application, though, I needed PhD's solution to prevent only one email from being linked.


I had the same problem, tried this:

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

it did not worked.

Then tried this:

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

and it did the trick


Hi Squeaggy why you do want to eliminate that funcionality from the webview, but well a tricky way would be including onClick="return false;" in the anchor tag that contains the email or URL.

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


That appears to be unchangeable functionality of the WebView.

You could do the opposite of this Is there any way to have WebView auto-link URLs and phone numbers in Android? and create a javascript link stripper (instead of the proposed link injector there).

Not sure what else would work for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜