开发者

How to stop Android browser from opening map when html has an address even if there is no anchor

I have addresses in html but without any anchors:

1111 10th Ave., Seattle WA 98112

When tapped in the Android browser, the map is opened. NOT the desired behavior. Preventing default onclick doesn't fix it. Preventing default on touchstart does fix it, but then the view doesn't scroll since scrolling is initialized ontouchstart.

How do I stop t开发者_如何学Gohis?

This is happens in the browser and in phonegap.


Adding these tags to the <head> are supposed to work:

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


The only way I can think of doing it is by modifying the text you display so it doesn't comply with the address rules: ergo, the browser won't consider them addresses and won't make them clickable. The address rules are currently like this (taken from the WebView source code at https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebView.java#1718):

/**
 * Gets the first substring consisting of the address of a physical
 * location. Currently, only addresses in the United States are detected,
 * and consist of:
 * <ul>
 *   <li>a house number</li>
 *   <li>a street name</li>
 *   <li>a street type (Road, Circle, etc), either spelled out or
 *       abbreviated</li>
 *   <li>a city name</li>
 *   <li>a state or territory, either spelled out or two-letter abbr</li>
 *   <li>an optional 5 digit or 9 digit zip code</li>
 * </ul>
 * All names must be correctly capitalized, and the zip code, if present,
 * must be valid for the state. The street type must be a standard USPS
 * spelling or abbreviation. The state or territory must also be spelled
 * or abbreviated using USPS standards. The house number may not exceed
 * five digits.
 *
 * @param addr the string to search for addresses
 * @return the address, or if no address is found, null
 */

Not sure what you would do: maybe insert extra invisible characters to break it up?


I tried masking it already with a html element on top of the address. No dice.

Thanks to @Femi, I added invisible characters. This adds a bit more of complexity as I will have to remove the extra characters after the user taps the address.

Basically this is a form picker view, they select an address from their trip itinerary to then be used in dining search.

The following html example solves this problem:

<div class="content">1111 Webster St. <span style="position: absolute; left: -9999px;">sdfsdfsdfsd</span> San Francisco, CA, 94117</div>

I can't believe I have to do this in my javascript:

locationString = "<span class='offToLeft'>sdfsdfsdfsd</span>"+locationString;

Boom! Take that Android map intent!


You could try

  • a transparent gif or an empty DEV element over the text
  • preventing onmousedown or onclick, instead of ontouchstart
  • putting a hidden SPAN element between the city and state with some dummy text in


There has got to be a better answer than the ones we're providing here. But I had the same problem so I just made the element into a hyperlink that pointed nowhere. So it overrides the map but doesn't take the user anywhere.

<a href="#">Some button</a>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜