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


当前回答

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中的电话检测。

其他回答

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

要禁用特定元素的电话解析外观,下面的CSS似乎可以做到:

.element { pointer-events: none; }
.element > a { text-decoration:none; color:inherit; }

第一条规则禁止单击,第二条规则负责样式化。

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

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

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

我自己测试过,发现它是有效的,尽管它肯定不是一个优雅的解决方案。在电话号码中插入空span将防止数据检测器将其转换为链接。

(604) 555<span></span> -4321

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

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