当html有地址时,即使没有锚点,如何阻止Android浏览器打开地图

发布于 2024-11-08 11:08:12 字数 247 浏览 1 评论 0原文

我有 html 格式的地址,但没有任何锚点:

1111 10th Ave., Seattle WA 98112

在 Android 浏览器中点击时,地图将打开。不是期望的行为。阻止默认 onclick 并不能解决问题。防止 touchstart 上的默认设置确实可以解决此问题,但由于滚动是在 touchstart 上初始化的,因此视图不会滚动。

我该如何阻止这个?

这发生在浏览器和phonegap 中。

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 this?

This is happens in the browser and in phonegap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

愚人国度 2024-11-15 11:08:12

将这些标签添加到 应该可以工作:

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

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

<meta name="format-detection" content="telephone=no"/>
<meta name="format-detection" content="address=no" />
深居我梦 2024-11-15 11:08:12

我能想到的唯一方法是修改您显示的文本,使其不符合地址规则:因此,浏览器不会将它们视为地址,也不会使其可点击。地址规则目前是这样的(取自 WebView 源代码 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
 */

不确定你会做什么:也许插入额外的隐形字符来打破它?

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?

星軌x 2024-11-15 11:08:12

我尝试在地址顶部使用 html 元素来屏蔽它。没有骰子。

感谢@Femi,我添加了隐形字符。这增加了一点复杂性,因为在用户点击地址后我必须删除多余的字符。

基本上,这是一个表单选择器视图,他们从旅行行程中选择一个地址,然后用于餐饮搜索。

以下 html 示例解决了此问题:

1111 Webster St. sdfsdfsdfsd San Francisco, CA, 94117

我不敢相信我必须在我的 javascript 中执行此操作:

locationString = "sdfsdfsdfsd" +locationString;

繁荣!以 Android 地图意图为例!

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!

萌︼了一个春 2024-11-15 11:08:12

您可以尝试

  • 在文本上使用透明 gif 或空 DEV 元素
  • 来防止 onmousedown 或 onclick,而不是 ontouchstart
  • 在城市和州之间放置一个隐藏的 SPAN 元素,并在其中添加一些虚拟文本

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
云归处 2024-11-15 11:08:12

一定有比我们在这里提供的更好的答案。但我遇到了同样的问题,所以我只是将该元素制作成一个指向任何地方的超链接。因此它会覆盖地图,但不会将用户带到任何地方。

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文