Open a new tab
Asked by Frances McDonald:

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..


Answers:
author: RambanamP
body: you can try like this

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

comments: author: RambanamP
body: if my answers helped then don't forgot to accept as answer:)


author: Frances McDonald
body: thank you this was the resolution and if statement for a space key..


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

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


author: RambanamP
body: check the following doc

[](https://confluence.atlassian.com/display/CONFKB/How+to+Force+Links+to+Open+in+a+New+Window)<https://confluence.atlassian.com/display/CONFKB/How+to+Force+Links+to+Open+in+a+New+Window>

comments: author: Frances McDonald
body: 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


author: Frances McDonald
body: 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


author: RambanamP
body: 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


author: Frances McDonald
body: 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


author: Nic Brough -Adaptavist-
body: 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.


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

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


author: Frances McDonald
body: can someone tell me how to put an "if" statement to the script please if spacekey is called "TO"


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


author: Frances McDonald
body: [](http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations)<http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations>

is this what you are looking for?thanks


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

or

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


author: Frances McDonald
body: |----------|-----------------------------------------------------------------------------------------------------------------------|
| \<html\> |
|          | \<head\>                                                                                                              |
|          | \<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 = '';                                                                                                 |
|          | \</script\>                                                                                                           |
|          |


author: Frances McDonald
body: from cntrl u

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| \<link rel="canonical" href="[](http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations)<http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations>"\> |
|                                                                                                                                                                          | \<link rel="shortlink" href="[](http://wiki.wonga.com/x/xY3pAw)<http://wiki.wonga.com/x/xY3pAw>"\> |


author: Frances McDonald
body: |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| \<link rel="canonical" href="[](http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations)<http://wiki.wonga.com/display/TO/Welcome+to+Technology+Operations>"\> |
|                                                                                                                                                                          |   |

\<link rel="shortlink"href="[](http://wiki.wonga.com/x/xY3pAw)<http://wiki.wonga.com/x/xY3pAw>"\>


author: Frances McDonald
body: I also tried to add this statement

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

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