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


当前回答

添加元标记来关闭格式检测对我来说不起作用。我试图在<p>标签和其他文本中显示缩放会议ID, iOS将该ID转换为电话链接。此外,我通过一个[href^="tel:"]定位电话链接,以便给他们自定义样式,因此禁用电话链接上的样式不是一个选项。

我找到的解决方案是将ID号包装在<code>标记中。这似乎可以防止iOS干扰它。

其他回答

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">

Sencha Touch的index.html中的meta标签(<meta name="format-detection" content="telephone=no">)解决了同样的问题。

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

我使用的一个不仅适用于Mobile Safari的技巧是使用HTML转义码和在电话号码中添加一点标记。这使得浏览器更难“识别”一个电话号码。

Phone: 1-8&#48;&#48;<span>-</span>62&#48;<span>-</span>38&#48;3