Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Link to new window in user macro

Виталий September 15, 2021

Hi!

As there is not way to add link to new (blank) page in Confluence i've desided to make my own macro for this purpose.

So my macro is:

## @Param URL:title=URL|type=string|required=true|desc=Target URL
## @Param Caption:title=Caption|type=string|required=true|desc=URL Caption

<a href="$!paramURL" target="_blank">$!paramCaption</a>

 

Pretty simple and it works fine, except one detail - it ignores the "target" attribute!

On the rendered page code looks like:

2021-09-15_17-13-38.png

1 answer

0 votes
Brant Schroeder
Community Champion
September 15, 2021

@Виталий 

Take a look at this article https://confluence.atlassian.com/confkb/how-do-i-make-my-attachments-open-in-a-new-window-or-tab-313459830.html

Looks like the target needs an _ in front of it.  You can try it and see if that works.

Виталий September 18, 2021

I'll try it, thanks!

For now i've done this macro and it worked:

 

## @Param Caption:title=Caption|type=string|required=true|desc=URL Caption
## @Param Link:title=Link|type=string|required=true|desc=Full URL Link
## @Param OpenType:title=OpenType|type=enum|required=false|enumValues=New window,Current window|default=New window|desc=Where to open link

#if ($paramOpenType == "New window")
#set ( $target = "_blank")
#elseif ($paramOpenType == "Current window")
#set ( $target = "_self")
#end

#set ($linkHtml = '<a href="'+$paramLink+'" target="'+$target+'">'+$paramCaption+'</a>')

<ac:structured-macro ac:name = "html">
<ac:plain-text-body>

<![CDATA[ $!linkHtml ]]>

</ac:plain-text-body>
</ac:structured-macro>

 

This is html macro wrapped in user macro, actually ^_^

Like Brant Schroeder likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events