Within a page and you have a "link" to another page I would like this page to open a new window/tab each time. I understand you can right click on the link and "open in ew tab" option but most people just click on the link and it uses the same page hence to view the instructions/content you have to back space each time. I would like an link to open a new page automatically. I belioeve this may not be good practise for certain reason so can you advise if it is good practise and how it can be done thanks..

2 answers

you can try like this

jQuery(document).ready(function() {
	if(AJS.$('#confluence-space-key').attr('content') == 'TO'){
		AJS.$(".wiki-content a").attr("target", "_blank");


if my answers helped then don't forgot to accept as answer:)

thank you this was the resolution and if statement for a space key..

Davin Studer Community Champion Jan 19, 2014

One slight edit that would future proof this a little would be to use the AJS.Meta.get method to get the space key.

jQuery(document).ready(function() {
    if(AJS.Meta.get("space-key") == 'TO'){
        AJS.$(".wiki-content a").attr("target", "_blank");

thanks for this..

Is there a way I can do it for a certain space key only rather than whole look and feel..can I amend the html code for just a certain space please..thanks

tried to edit the target space details and chose space admin. I do not see anyway of choosing "custom html" within this space only under the Look and Feel

it will be on Administration >> Custom HTML not on the target space details.

if you don't have administration permission then ask your confluence administartor to add the script

but will this change the issue for all spaces..I only want to do it for a space for my area and not the complete look and feel for all spaces ?thanks

You'll need to put an "if" statement into the javascript to detect the current space and only activate if it matches the spaces you need it for.

For what it's worth though, opening in a new window/tab every time is a royal pain in the neck for most users as you quickly litter their workspaces with pages they don't care about any more. It should be used sparingly, not on every link.

but where will the if statement lie within here if the Space key is called "TO":

jQuery(document).ready(function() {
jQuery(".wiki-content a").attr("target", "_blank");

can someone tell me how to put an "if" statement to the script please if spacekey is called "TO"

if you provide UI source code of space key then i can able to help you, because i don't confluence on my machine!!

use firebug on firefox or JavaScript console on chrome and get the HTML code for that link


press Ctrl + u it will give source code of entaire page, from that you can copy the html code for that link

<title>Welcome to Technology Operations - Technology Operations - Wonga Wiki</title>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE,chrome=IE7">
<meta charset="UTF-8">
<!-- Deprecated since 3.4. To be removed in a future version of Confluence; use AJS.Confluence.getContextPath() -->
<meta id="confluence-context-path" name="confluence-context-path" content="">
<meta id="confluence-base-url" name="confluence-base-url" content="http://wiki.wonga.com">
<meta id="atlassian-token" name="atlassian-token" content="69a6a0c404663e80828d3067ad47341ff39fc514">
<meta id="confluence-space-key" name="confluence-space-key" content="TO">
<script type="text/javascript">
// Deprecated global variables. To be removed in a future version of Confluence.
var contextPath = '';

I also tried to add this statement

#if (AJS.params.spaceKey == 'TO')

to what you suggested as space key is TO na ddidnt work..

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,030 views 51 8
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