Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript Confluence Source Editor

Charisma Riley
Contributor
October 20, 2018

@Stephen Deutsch and anyone else who might be able to help: This script here: (https://community.atlassian.com/t5/Confluence-questions/Editing-Source-Code-in-Confluence/qaq-p/129384 works flawlessly. However, for some reason, whenever I try to add `<script>` or `<link>` it throws me an error until I pull it out. Is there any way to force those tags through? Or maybe a way to rewrite the script so that it allows scripting in the `<head>` section or something and I can use `<link>`? We really just need the ability to import JS into our pages. I mentioned Stephen soecifucally because his script has been the absolute closest we've ever been able to come! But truly, any help anybody here can give is be sincerely (and whole-heartedly) appreciated.

Thanks to everyone in advance!

1 answer

1 accepted

0 votes
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 24, 2018

Hey Charisma,

That is a really slick workaround - wish I'd known about that while I was still a Confluence administrator!

For your point of injecting in <head> - unfortunately that won't work here as the page content is stored in the database and rendered into a specific place in the page template. Stephen's clever script is making an API call to overwrite the body content, so it simply doesn't get access to other parts of the page.

In Server, a Confluence administrator can enable the HTML macro and then use it to insert Javascript on pages. In Server you can also add Custom HTML from the Confluence Admin menu and inject a file from disk (including javascript files) - example provided on that same document. Just be aware that using the Custom HTML way of adding Javascript adds it to every page, so you might need to include some checks in the Javascript itself to only execute on certain URLs.

However for you Charisma, I believe you're currently on Cloud. A few other threads have been raised in the past asking "why" on the lack of a built-in HTML macro for Cloud, and the short answer is that the Cloud environments are shared, so it's not there for both security and stability reasons.

There are at least two marketplace add-ons that provide HTML macros that also let you inject Javascript though:

I know it's a bummer that it's not built in for Cloud, and I definitely am sensitive to having a small budget and feeling like every extra plugin is a hidden cost that you weren't planning on. However having worked with paid marketplace vendors in the past, I can attest that Marketplace apps have a lot of flexibility in terms of features and roadmap. You have a lot of power to make suggestions for marketplace apps that you might see added in mere days in some cases. And there is little chance of a paid add-on being removed in the future.

I hope that helps!

Cheers,
Daniel

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events