当html有地址时,即使没有锚点,如何阻止Android浏览器打开地图
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将这些标签添加到
应该可以工作:
Adding these tags to the
<head>
are supposed to work:我能想到的唯一方法是修改您显示的文本,使其不符合地址规则:因此,浏览器不会将它们视为地址,也不会使其可点击。地址规则目前是这样的(取自 WebView 源代码 https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebView.java#1718):
不确定你会做什么:也许插入额外的隐形字符来打破它?
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):
Not sure what you would do: maybe insert extra invisible characters to break it up?
我尝试在地址顶部使用 html 元素来屏蔽它。没有骰子。
感谢@Femi,我添加了隐形字符。这增加了一点复杂性,因为在用户点击地址后我必须删除多余的字符。
基本上,这是一个表单选择器视图,他们从旅行行程中选择一个地址,然后用于餐饮搜索。
以下 html 示例解决了此问题:
我不敢相信我必须在我的 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!
您可以尝试
You could try
一定有比我们在这里提供的更好的答案。但我遇到了同样的问题,所以我只是将该元素制作成一个指向任何地方的超链接。因此它会覆盖地图,但不会将用户带到任何地方。
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.