Forums

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

How do I make links within a children display open in a new tab

mauro chacón
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2018

I've got a few pages within our org's space that have children display macros embedded.  I've looked all over and cannot find a way to make the links, within the children display macro, to open in a new tab. 

I do not have access to the header for embedding additional code and would like to know if I can include the necessary code via stylesheet.

Where can I access the links within the child display macro for editing?  I'm taking up this role and had little to no training.

2 answers

2 votes
David at David Simpson Apps
Atlassian Partner
May 15, 2018

Unfortunately, you can only style things in a stylesheet. You cannot change the behaviour of items on the page.

To get this working, you'll need to get access to adding Custom HTML to your Confluence Server instance.

In Confluence Admin | Look and Feel | Custom HTML

Paste the following in At the END of the HEAD field:

<script>
AJS.toInit(function ($) {
$('.childpages-macro a').attr('target', '_blank');
});
</script>

To do it just for a specific space, then you'd need to get the space name or key added to this logic, e.g. for the personal space with space key of ~david

<script>
AJS.toInit(function ($) {
if (AJS.params && AJS.params.spaceKey && AJS.params.spaceKey === '~david') {
$('.childpages-macro a').attr('target', '_blank');
}
});
</script>

I hope this helps a little.

1 vote
Thomas Schlegel
Community Champion
May 15, 2018

Hi @mauro chacón,

if you are able to create a user macro, you can wrap the children macro into a script that will open the links in a new tab:

This is the code of the user-macro:

## @noparams

<script>
jQuery(document).ready(function() {
jQuery(".wiki-content a").attr("target", "_blank");
});
</script>

<ac:structured-macro ac:name="children"/>

Save the macro as "children-external" and put that macro to your page. 

As a result, every link on your page will open in a new window. That means, every link. Not only the ones from your children-macro. 

If you have further questions regarding user macros, don't hesitate to ask.

David at David Simpson Apps
Atlassian Partner
May 15, 2018

Nice, but for just the links in the children macro to open in a new tab/window, I'd target them specifically:

## @noparams

<script>

AJS.toInit(function ($) {
$('.childpages-macro a').attr('target', '_blank');
});
</script>

<ac:structured-macro ac:name="children"/>
Thomas Schlegel
Community Champion
May 15, 2018

That's great, @David at David Simpson Apps - thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events