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


当前回答

我的经历和其他人提到的一样。元标签…

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

...当网站运行在移动Safari(即,chrome),但停止工作时,运行作为一个网络应用程序(即,被保存到主屏幕和运行没有chrome)。

我不太理想的解决方案是将值插入输入字段…

<input type="text" readonly="readonly" style="border:none;" value="3105551212">

这不是很理想,因为尽管边界被设置为none, iOS在字段上方呈现一个多像素的灰色条。但是,这比把数字看作一个链接要好。

其他回答

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

我有一个ABN(澳大利亚商业号码),iPad Safari坚持要把它变成一个电话号码链接。这些建议都没用。我的解决方案是在数字之间加上img标签。

ABN 98<img class="PreventSafariFromTurningIntoLink" /> 009<img /> 675<img /> 709

该类的存在只是为了记录img标记的用途。

适用于iPad 1(4.3.1)和iPad 2(4.3.3)。

我也有同样的问题。我在UIWebView中找到了一个属性,它允许你关闭数据检测器。

self.webView.dataDetectorTypes = UIDataDetectorTypeNone;