Open PDF in new window/tab

Hi All,

I know this has been asked before but I haven't had any success with the exsiting answers.


I am trying to make links to attachments (mainly pdf's) open in a new browser tab/window.
I successfully did this for external links using the custon html instructions here.

I would like to modify the code below to be only for attachments not all wiki content.

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

Any ideas?

Thanks,

Alicia

2 answers

1 accepted

Hey, so I tried the above script (and also the Bitvoodoo External Link plugin) and it didn't work. 

The script was running fine and "target""_blank" was being applied to the links but it still wasn't working. 

I contacted atlassian support and received this response:

 

So it looks like this was a change made in 5.2 because of the possibility of XSS that resulted in a bunch of different file types now defaulting to opening a save dialog. The good news is that this is configurable, if you're happy taking on the risk presented by XSS. To allow PDFs to open in the browser automatically:

1. Click on cog at the Confluence header and choose "Confluence Admin"
2. Under "Users & Security" choose "Security Configuration".
3. Click any of the "Edit" buttons on the page and find the "Attachment Download Security Policy" section.
4. Select the "Insecure: Display all attachments inline" option and click "Save".

For more information, please see CONF-29277.

 

It is working fine now!

 

Thanks,

Alicia

I believe that you can distinguish the attachments links from the other links by the URL. The attachments will be the ones with the URLs that begin with “/confluence/download/attachments/”. If that’s the case, you could use

<script>
jQuery(document).ready(function() {
    jQuery(".wiki-content a[href^='\\/confluence\\/download\\/attachments\\/']").attr("target", "_blank");
});
</script>

If I’ve gotten the URLs wrong you can change the jQuery selector appropriately.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,777 views 25 10
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