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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.