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

其他回答

你可以尝试将它们编码为HTML实体:

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

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

截至2012年6月13日,这个答案胜过一切:

<a href="#" style="color: #666666; 
                   text-decoration: none;
                   pointer-events: none;">
  Boca Raton, FL 33487
</a>

将颜色更改为与文本匹配的颜色,文本装饰删除下划线,指针事件阻止它像浏览器中的链接一样被查看(指针不会更改为手)

这是完美的HTML电子邮件在ios和浏览器。

我使用零宽度细木工&zwj;

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

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

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

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