简体   繁体   English

锚链接仅在浏览器中有效,而在 HTML 电子邮件中无效(Outlook)

[英]Anchor links only working in browser but not in in HTML email (Outlook)

I have an HTML email generated from a Windows application.我有一个从 Windows 应用程序生成的 HTML 电子邮件。 The template used for this is designed in .aspx page.用于此的模板是在 .aspx 页面中设计的。 The email has some links at top of the page which should take the user to a detailed description to the end of the same email.电子邮件在页面顶部有一些链接,可以将用户带到同一电子邮件末尾的详细说明。 This works fine in the browser but doesn't work in Outlook.这在浏览器中运行良好,但在 Outlook 中不起作用。

<a href="#Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters">Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters</a>

The above anchor tag, when clicked, should go here上面的锚标签,当点击时,应该到这里

<b id="Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters" class="sectionheadline">Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters</b>
<br>
in.reuters.com—March 03, 2014
<br>
<br>
&quot;BOSTON, March 3 (Reuters) - Alsop Louie Partners led a $9 million investment in Wickr, a San Francisco-based startup founded by privacy advocates in 2012 that produces a mobile app for sending self-destructing text, photo and video messages. Gilman...<br><br>.

In View source the id in tag and href in tag match, but in an email when hovered over the link the address has '_' instead of spaces, which is why the links are not working.在查看源代码中,标签中的 id 和标签中的 href 匹配,但在电子邮件中,当鼠标悬停在链接上时,地址有“_”而不是空格,这就是链接不起作用的原因。

So you have coded your anchor tags like such:所以你已经编码了你的锚标签,如下所示:

<a name="test">Wickr raises $9 mln</a>
<a href="#test>Wickr raises $9 mln</a>

And this is still not working?这仍然不起作用? You should also have a look at campaign monitor for supported browsers.您还应该查看支持浏览器的活动监视器。 I haven't coded emails in a while, but I remember it was always quite a hassle.我有一段时间没有编写电子邮件,但我记得这总是很麻烦。

I found that placing the tag我发现放置标签

<base href="" />

in the head section worked for me (Outlook 2013) with the standard anchor tag.在 head 部分使用标准锚标记为我工作(Outlook 2013)。 I found this fix on this page CampaignMonitor我在此页面上找到了此修复程序CampaignMonitor

I tested the following code in Outlook2007 and Outlook2013.我在 Outlook2007 和 Outlook2013 中测试了以下代码。 It works.有用。

The anchor tag:锚标签:

<a href="#Test Link">Test Link</a>

And the Target:和目标:

<p><a name="Test Link"></a>Test Link</p>

The id/name attribute is like a variable name, for more cross compatible support it really should not have symbols or spaces in the first place. id/name 属性就像一个变量名,为了更多的交叉兼容支持,它首先不应该有符号或空格。

Think how that would look in the address bar:想想地址栏中的样子:

  • webpage.html#Wickr%20raises%20%249%20mln%20as%20Alsop%20Louie%2C%20Juniper%20Networks%20invest%20%7C%20Reuters%20 web.html#Wickr%20raises%20%249%20mln%20as%20Alsop%20Louie%2C%20Juniper%20Networks%20invest%20%7C%20Reuters%20

So I guess the silly answer is not to use spaces... That being said, I've noticed both outlook and winword will edit your hyperlink in different ways depending on the prefix "File:" or "http:".所以我想愚蠢的答案是不使用空格...话虽如此,我注意到 Outlook 和 winword 都会根据前缀“文件:”或“http:”以不同的方式编辑您的超链接。 Hopefully that helps.希望这有帮助。

While they work in just about every browser, support for anchor links is a mixed bag in email clients .虽然它们几乎适用于所有浏览器,但对锚链接的支持在电子邮件客户端中却是喜忧参半 Even though that link says Outlook 2007 (2010 and 2013 are the same) support anchor links, their behavior is unreliable at best.尽管该链接表示 Outlook 2007(2010 和 2013 相同)支持锚链接,但它们的行为充其量是不可靠的。

Simplifying the anchor's <a href=""> increases your coverage.简化锚的<a href="">增加您的覆盖范围。 Eg changing something like this:例如改变这样的事情:

<a href="#Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters">Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters</a>

to this:对此:

<a href="#first">Wickr raises $9 mln as Alsop Louie, Juniper Networks invest | Reuters</a>

Email clients might trip over spaces and special characters.电子邮件客户端可能会被空格和特殊字符绊倒。

Sample PDF示例 PDF

'<base href="" />' 

Adding the base tag in header and add the name attribute in anchor work for me在标题中添加基本标签并在锚点中添加名称属性为我工作

Try to always give http at the start of the URL as follows,尝试始终在 URL 开头给出http ,如下所示,

<a href="http://www.website.com/"></a>

If not it will not work in outlook.如果不是,它将无法在 Outlook 中工作。 It worked for me.它对我有用。 Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM