【问题标题】:Blue links issue on Gmail and iOS email clientsGmail 和 iOS 电子邮件客户端上的蓝色链接问题
【发布时间】:2018-09-23 18:56:47
【问题描述】:

我正在构建 html 电子邮件,我知道这是一个已知问题,我尝试了许多解决方案来强制地址/电话/电子邮件文本不改变颜色并成为 Gmail 和 ios 上的链接。唯一对我有用的解决方案是将我的文本和标签和样式放在里面,以获得我需要的字体颜色。这是我的例子:

...<tr><td bgcolor="#F2F2F2" align="center" style="color:#3C3D3F;line-height:24px;font-family:Tahoma, Arial, Helvetica, sans-serif;padding:15px 10px;font-size:12px;"><a href="" style="outline:none;color:#3C3D3F;cursor:initial;text-decoration:none;"><span style="color:#3C3D3F;">128 Prinston St | Somewhere, CA 22314</span></a></td></tr>...

从某种意义上说,这是我需要的字体颜色,但我不想将此文本作为链接。现在我必须将 href 属性留空,当单击 iOS 默认电子邮件中的文本时,该属性会指向白页。

所以请建议任何不需要在代码中包含标签的可行解决方案。

提前致谢。

【问题讨论】:

    标签: ios colors hyperlink gmail html-email


    【解决方案1】:

    如果您不想要那个蓝色下划线,那么在制作电子邮件时,数据检测器就会变得非常痛苦。我有几种技巧建议您尝试一下。

    将以下内容放在电子邮件的&lt;head&gt;&lt;/head&gt; 部分。如果您已经有 &lt;style&gt;&lt;/style&gt; 部分,请在此处添加:

        <style>
        *[x-apple-data-detectors], .x-gmail-data-detectors, .x-gmail-data-detectors *, .aBn {
            border-bottom: 0 !important;
            cursor: default !important;
            color: inherit !important;
            text-decoration: none !important;
            font-size: inherit !important;
            font-family: inherit !important;
            font-weight: inherit !important;
            line-height: inherit !important;
        }
        </style>
    

    如果这不能解决问题,您总是可以在带下划线的区域周围做类似的事情:

    <span style="color: inherit !important; text-decoration: none !important; ">your content here</span>
    

    可能会解决此问题的一件事是将 META 标记添加到 &lt;head&gt;&lt;/head&gt; 区域:

    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <meta name="x-apple-disable-message-reformatting" />
    

    如果所有其他方法都失败(并且我遇到了所有其他方法都失败的问题),我发现添加非打印字符可能有助于阻止数据检测器检测 url、电话号码、地址或日期。

    &amp;zwnj;

    对此的变体通常是有效的:

    gwally&zwnj;@&zwnj;stackoverflow&zwnj;.&zwnj;com
    

    祝你好运,难看的蓝线。

    【讨论】:

    【解决方案2】:

    如何为链接附加一个通用样式。

    <style> a:link { color: #3C3D3F; } </style>
    

    代码:

    NSString *styledHTML =  [@"<style> a:link { color: #3C3D3F; } </style>" stringByAppendingString:originalHTMLString];
    

    或

    NSRange rOriginal    = [originalHTMLString rangeOfString:@"<tr>"];
    NSString *styledHTML = [originalHTMLString stringByReplacingCharactersInRange:rOriginal withString:@"<tr><style> a:link { color: #dc3535; } </style>"];
    

    【讨论】:

    • 感谢您的回答,我正在构建 HTML 电子邮件,不确定此代码是否有效,您建议在哪里编写?
    • 追加到您的 html 中的任何位置。
    • 该代码破坏了模板。它们根本不会显示在电子邮件客户端上。至于一般只指定链接的颜色,我已经指定了,但它没有帮助。
    猜你喜欢
    • 2018-11-15
    • 2019-05-19
    • 1970-01-01
    • 2022-06-28
    • 2013-11-23
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    相关资源
    最近更新 更多