Confluence jira-issue macro links to open in a new window

http://jsfiddle.net/buDxG/

See above link for a working sample where the links inside jira-issue macro are properly having the target attribute set to _blank. However, when this is actually added to the end of the HEAD via Custom HTML, inspecting jira-issue links shows that the target is "" (no value).

Is there any way to have jira-issue links open in a new tab/window?

Confluence 5.1 with minimal customization or other plugins installed.

<!-- open external links in a new window -->
<script>
jQuery(document).ready(function() {
    jQuery(".external-link").attr("target", "_blank");
    jQuery(".jira-issue a").attr("target", "_blank");
});
</script>

2 answers

Confluence 5.1 with minimal other customization.

Hey Matt,

In theory this should work. I attempted a similar method internally (using the HTML Macro) and it worked fine.

I would try a couple things (following from: https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluence)

1. While it's nitpicking, I would add a: type="text/javascript" to your script tag.

2. Confluence wraps jQuery in another function, AJS. You can use all the jQuery functionality by calling something like

AJS.$('div.foo');

I would modify your jQuery calls using AJS instead. You can test if this works by throwing an alert() or console.log() function inside your .ready() call, to confirm that your function is firing off as expected.

I've changed to the below code which is at least working in Firefox and Chrome (after you wait a while for the load even to fire). This is not working in IE and I'm not sure how you got yours to work with the ready event as I still can't get it to work in any browser with that event.

<!-- open external links in a new window -->
<script type="text/javascript">
AJS.$(document).ready(function() {
    AJS.$(".external-link").attr("target", "_blank");
});
AJS.$(window).load(function() {
    AJS.$(".jira-issue a").attr("target", "_blank");
});
</script>

Neal, what theme were you using during testing? I've seen a Chrome editor bug fix not work in with the newest documentation theme. Maybe this is something that only works in the new theme?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,557 views 26 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you