Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office 365 and Outlook.com strip <a> tags with empty or invalid href attributes #10

Open
hteumeuleu opened this issue Dec 28, 2015 · 8 comments
Labels
Outlook Windows, macOS, iOS, Android and Outlook.com

Comments

@hteumeuleu
Copy link
Owner

When Office 365 and the new Outlook.com encounter an empty href, it will remove the <a> tag but leave its content. For example…

<a href="">Hello world</a>

… would become :

Hello world

When you have any content other than a URL inside a href, Office 365 and the new Outlook.com will show this content inside the email between brackets. So the following example…

<a href="Hello">world</a>

… would become :

[Hello]world

This bug was discussed on Litmus Forums here.

@hteumeuleu hteumeuleu added the bug label Dec 28, 2015
@hteumeuleu hteumeuleu changed the title Office 365 strips <a> tags with empty or invalid href attributes Office 365 and Outlook.com strip <a> tags with empty or invalid href attributes Mar 15, 2016
@kate-stoner
Copy link

Thanks!

@hteumeuleu
Copy link
Owner Author

This bug gets even weirder when combining styles. It turns out the styles applied to a problematic <a> tag will be applied on the first element after in the code that has a style attribute.

Huge thanks to @bago at Mosaico for writing about this. Here's an example from their post:

<a style="color: red; background-color: yellow;"></a>
<p>A paragraph</p>
<p>Second paragraph with no style</p>
<p style="">Third paragraph with style</p>
<p style="">Fourth paragraph with style</p>

On Outlook.com, this becomes:

<p>A paragraph</p>
<p>Second paragraph with no style</p>
<p style="color: red; background-color: yellow;">Third paragraph with style</p>
<p style="">Fourth paragraph with style</p>

It looks like any style in an invalid <a> tag will be pushed to some sort of styles array. And then, on the first all those styles will be flushed on the first element with a style attribute. So the following example:

<a style="color: cyan; background-color: cyan;">cyan</a>
<a style="color: purple; background-color: purple;">purple</a>
<a style="color: black; background-color: black;">black</a>

<p style="">Empty style 1</p>
<p style="">Empty style 2</p>
<p style="">Empty style 3</p>

…becomes:

<p style="color: cyan; background-color: cyan; color: purple; background-color: purple; color: black; background-color: black;">Empty style 1</p>
<p style="">Empty style 2</p>
<p style="">Empty style 3</p>

@hteumeuleu hteumeuleu added Outlook Windows, macOS, iOS, Android and Outlook.com and removed bug labels Jul 10, 2019
@tsturtz
Copy link

tsturtz commented Dec 10, 2019

Thank you @hteumeuleu - it was so hard to find information on this. It was doing this with my http:// href value (localhost) ... 😕 (I assume because https is standard now)

@jkupczak
Copy link

jkupczak commented Mar 30, 2021

I'm not seeing the style bug anymore on Outlook.com. I tested the following code:

<a style="color: red; background-color: yellow;"></a>
<p>A paragraph</p>
<p>Second paragraph with no style</p>
<p style="">Third paragraph with style</p>
<p style="">Fourth paragraph with style</p>

Outlook is still stripping the tag though.

@hteumeuleu
Copy link
Owner Author

Sounds about right! I see the same thing. Thanks for the notification. I'm closing this for now.

@hteumeuleu
Copy link
Owner Author

Wait… I closed this bug because the styles sub-bug noted here was fixed. But the main problem listed on the first post is still live and well. So this bug should still be open.

@hteumeuleu hteumeuleu reopened this Sep 24, 2021
@lidialodovici
Copy link

How to fix this when href is dynamic? the anchor is defined by a handlebar variable

@revelt
Copy link

revelt commented Aug 16, 2022

@lidialodovici do you mean "dev" (pre-production) template builds? If so, if you don't have the means to get templates rendered on ESP-side, there are two options: either render the template locally somehow (I go that approach myself, render Nunjucks templates locally, using mock data files, in Gulp) or find and replace all href before sending it out to test:

const regx = /href="{{[^}]+}}/g;
const inp = `{{dont replace me}} <a href="{{foo}}">click</a>`;
console.log(inp.replace(regx, `href="http://test.com`));
// => {{dont replace me}} <a href="http://test.com">click</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Outlook Windows, macOS, iOS, Android and Outlook.com
Projects
None yet
Development

No branches or pull requests

6 participants