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.

其他回答

我使用零宽度细木工‍

把这句话放在电话号码里就行了。在BrowserStack(和Litmus用于电子邮件)中测试。

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

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

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

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

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">)解决了同样的问题。