5

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?

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

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
  • Why do you want to suppress this behaviour? It seems pretty reasonable that all email addresses on a device whose primary purpose is communication should be clickable to send an email... – Dan Davies Brackett Jul 06 '10 at 18:08
  • I have 100% control over the content of this WebView. and I don't want it doing things I don't tell it to. If I want an email address clickable, I will make it so. Also, in my setup, it highlights but is overridden by event handlers that prevent it from actually firing here. Mainly I want explicit control over this behavior. Especially since it does D-pad highlighting as well. And iPhone's `UIWebView` lets you turn it off: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIWebView/dataDetectorTypes – Alex Wayne Jul 06 '10 at 18:50

5 Answers5

6

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;
    }
});
Paaske
  • 4,345
  • 1
  • 21
  • 33
2

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.

Michael
  • 8,362
  • 6
  • 61
  • 88
1

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

PhD
  • 11
  • 1
0

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>
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
-1

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.

Community
  • 1
  • 1
kiswa
  • 14,737
  • 1
  • 21
  • 29