How to make Confluence open a new tab when clicking on the attachments link

Opening attachments will result in a new tab, leaving the page it is attached to open in other tab.

Solution

Modifying the template file in confluence-attachments-plugin-x.x.jar (in this case, I try on confluence-attachments-plugin-2.10.jar). Please edit attachmentsmacro.vm file. This file is located in confluence-attachments-plugin-2.10.jar file. Extract this file by using the Editing files within .jar archives guide guide.

If you are able to extract it successfully, you can locate to attachmentsmacro.vm file and find the following lines:

<td><a name="$generalUtil.urlEncode($page.title)-attachment-$generalUtil.urlEncode($attachment.fileName)">#parse 
("/pages/includes/attachment_icon.vm")</a> <a href="$req.contextPath$attachment.downloadPathWithoutVersion">
$attachment.fileName</a></td>

and change the above code to be:

<td><a name="$generalUtil.urlEncode($page.title)-attachment-$generalUtil.urlEncode($attachment.fileName)">#parse 
("/pages/includes/attachment_icon.vm")</a> <a target="_blank" href="$req.contextPath$attachment.
downloadPathWithoutVersion">$attachment.fileName</a></td>

After making changes, please repack the file by following the steps here.

For newer Confluence versions:

  • For List Attachments page under Space (via Space >> Browse >> Attachments), the file to be edited can be found at:
    <confluence-install>/confluence/pages/listattachmentsforspace.vm. Find for the following lines of code:

    <a href="$req.contextPath$!attachment.downloadPathWithoutVersion">$generalUtil.shortenString($attachment.fileName, 50)</a>
    

    and change it to

    <a target="_blank" href="$req.contextPath$!attachment.downloadPathWithoutVersion">$generalUtil.shortenString($attachment.fileName, 50)</a>
    
  • For Attachments page under Page (via Page >> Tools >> Attachments), the file to be edited can be found at:
    <confluence-install>/confluence/pages/includes/attachments-table.vm. Find for the following lines of code:

                    <a class="filename" href="$generalUtil.htmlEncode("${req.contextPath}${attachment.downloadPathWithoutVersion}")"
                       title="$generalUtil.htmlEncodeAndReplaceSpaces($attachment.fileName)"
                       data-filename="$generalUtil.htmlEncode($attachment.fileName)">
                        $generalUtil.htmlEncode($generalUtil.shortenString($attachment.fileName, 35))
                    </a>
    

    and change it to

                    <a class="filename" target="_blank" href="$generalUtil.htmlEncode("${req.contextPath}${attachment.downloadPathWithoutVersion}")"
                       title="$generalUtil.htmlEncodeAndReplaceSpaces($attachment.fileName)"
                       data-filename="$generalUtil.htmlEncode($attachment.fileName)">
                        $generalUtil.htmlEncode($generalUtil.shortenString($attachment.fileName, 35))
                    </a>
    

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport