Access Javascript files from the HTML Macro

Is it possible to reference in a <script> tag an attached JS file from the HTML macro? And if it is what is the path to the JS file?

What I want is to be able to reference JS files from a page without having any admin rights.

2 answers

Hmm I do not think you can because when you attach a file it becomes 'text/plain' so you can't execute it.  If you can either change the MIME type checking or convert the text file into an executable when you fetch it, I am not sure if it is possible.  

I had this issue with a JS file (I wanted table filters but refused to by the addon just for a small feature) so I ended up directly linking to the person's github file.  You could try that, use github to store your js and pull it using the rawgit link.

This works for me in the HTML macro "<script type="text/javascript" src="http://URL/directory/example.js"></script>"

 

The js file needs to be in the Confluence directory, eg a js folder. A URL worked for me while a filepath didn't. 

 

See https://answers.atlassian.com/questions/33136690/executing-javascript-on-a-single-page

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

346 views 20 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