简体   繁体   中英

mailto: and tel: in android webbrowser

I am developing a html webpage for show in an android/ios/windows phone app inside a webview.

I have this kind of links: and the same with mailto:"mail@mail.com"

In ios works fine, also in chrome, firefox... But in webviews's webbrowser in android detects it as normal link and shows an inexistent webpage (This url cannot be found bla bla bla)

Is there a way to avoid this in android? or should I detect browser in javascript and load the href or not?

I found this for javascript: var browser = navigator.appName;

But I read this is not a good practice.

Disable the automatic Linkify of Webview

There is a way to do that - rather ugly, two layered, but still a workaround.

You should

  1. modify how the webview will handle the auto-linkifiable items
  2. explicitly tell the loaded page not to apply styles and haptic feedback

     mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { Uri uri = Uri.parse(url); if (url.startsWith("http:") || url.startsWith("https:")) { return false; } //TODO analyse the uri here //and exclude phone and email from triggering any action return false; } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {} public void onPageFinished (WebView view, String url) {...} public void onPageStarted(WebView view, String url, Bitmap favicon) {...} public void onLoadResource(WebView view, String url) {...} }); 

In the html specify the following meta tags inside the tag:

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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