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


当前回答

为什么要删除链接,这使得它非常用户友好的选择。

如果你只是想删除自动编辑,但保持链接工作,只需添加到您的CSS…

a[href^=tel] {
 color: inherit;
 text-decoration:inherit;
}

其他回答

根据Safari HTML参考,这似乎是正确的事情:

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

如果您禁用了此功能,但仍然需要电话链接,则仍然可以使用“tel”URI方案。

这里是苹果开发者库的相关页面。

<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的每一个纵向/横向组合进行媒体查询

Webview解决方案!

对于PhoneGap-iPhone / PhoneGap-iOS应用程序,您可以通过在项目的应用程序委托中添加以下内容来禁用电话号码检测:

// ...

- (void)webViewDidStartLoad:(UIWebView *)theWebView 
{
    // disable telephone detection, basically <meta name="format-detection" content="telephone=no" />
    theWebView.dataDetectorTypes = UIDataDetectorTypeAll ^ UIDataDetectorTypePhoneNumber;

    return [ super webViewDidStartLoad:theWebView ];
}

// ...

来源:禁用PhoneGap-iOS中的电话检测。

加上这个,我想这就是你想要的:

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

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

不幸的是,既不……

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

也不……

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

... 工作。

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

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

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

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

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