iPhone上的Safari会自动为出现在电话号码中的数字字符串创建链接。我正在编写一个包含IP地址的网页,Safari将其转换为电话号码链接。是否可以为整个页面或页面上的某个元素禁用此行为?


当前回答

I too have this problem: Safari and other mobile browsers transform the VAT IDs into phone numbers. So I want a clean method to avoid it on a single element, not the whole page (or site). I'm sharing a possible solution I found, it is suboptimal but still it is pretty viable: I put, inside the number I don't want to become a tel: link, the ⁠ HTML entity which is the Word-Joiner invisible character. I tried to stay more semantic (well, at least a sort of) by putting this char in some meaning spot, e.g. for the VAT ID I chose to put it between the different groups of digit according to its format so for an Italian VAT I wrote: 0613605⁠048⁠8 which renders in 0613605⁠048⁠8 and it is not transformed in a telephone number.

其他回答

你可以尝试将它们编码为HTML实体:

0 = 0
9 = 9

要在页面的某些部分禁用电话号码检测,请使用href="#"将受影响的文本包装在锚定标记中。如果你这样做,移动Safari和UIWebView应该不去管它。

<a href="#"> 1234567 </a>

我想我已经找到了一个解决方案:把数字放在<label>元素内。没有尝试任何其他标记,但是<div>使它在主屏幕上处于活动状态,即使有电话=no属性。

从之前的评论中可以明显看出,元标签确实起作用了,但由于某种原因,在iOS的后续版本中,至少在某些条件下,它已经失效了。我运行的是4.0.1。

<meta name = "format-detection" content = "telephone=no">对电子邮件不起作用:如果你正在准备的HTML是电子邮件,元标签将被忽略。

如果你的目标是电子邮件,这里还有一个丑陋但有效的解决方案:

一些你想避免链接或自动格式化的HTML的例子:

will cease operations <span class='ios-avoid-format'>on June 1,
2012</span><span></span>.

和CSS,将使魔术发生:

@media only screen and (device-width: 768px) and (orientation:portrait){
span.ios-date{display:none;}
span.ios-date + span:after{content:"on June 1, 2012";}
}

缺点:你可能需要对ipad/iphone的每一个纵向/横向组合进行媒体查询

我也遇到了同样的问题,不过是在iPad网页应用上。

不幸的是,既不……

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

也不……

&#48; = 0
&#57; = 9

... 工作。

但是,这里有三个丑陋的技巧:

用字母“O”代替数字“0” 用字母“l”代替数字“1” 插入一个没有意义的span:例如555.5<span>5</span>5.5555

取决于你使用的字体,前两个几乎不明显。后者显然包含多余的代码,但对用户是不可见的。

这当然是拙劣的技巧,如果您从数据动态生成代码,或者如果您不能以这种方式污染数据,那么这可能是不可行的。

但在紧要关头,这已经足够了。