detect http or https and apply target="_blank"

Duncan Koza asked on February 26, 2020 20:56

I am trying to build out a hyperlink and want to add target="_blank" only if the link contains http or https in the url? Is there a macro for that?

Example: {% if (BannerImageLink "starts with http or https") {"target=\"_blank\""} %}

Correct Answer

Brenden Kehren answered on February 26, 2020 22:56

You can do something like this:

<a href="{%BannerImageLink%}"{%if (BannerImageLink.StartsWith("http")) { " target='_blank'"}%}>Link text</a>

Here's a really good article on using the Macro Console.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Duncan Koza answered on February 26, 2020 23:48

Thank you so much. that is exactly what I was looking for. And thank for the link too.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.