JavaScript Confluence Source Editor
Asked by Charisma Riley:

[@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490) 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!


Answers:
author: Daniel Eads
body: 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](https://confluence.atlassian.com/doc/html-macro-38273085.html) and then use it to [insert Javascript on pages](https://confluence.atlassian.com/confkb/how-to-use-javascript-in-confluence-313458839.html). 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](https://confluence.atlassian.com/confkb/how-to-use-javascript-in-confluence-313458839.html). 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](https://community.atlassian.com/t5/Confluence-questions/HTML-Macro-for-Confluence-Cloud/qaq-p/104061) 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:

* [HTML Macro for Confluence Cloud](https://marketplace.atlassian.com/apps/1212279/html-macro-for-confluence-cloud?hosting=cloud&tab=overview)
* [Macro Toolbox (HTML, Tabs, Expand)](https://marketplace.atlassian.com/apps/1215202/macro-toolbox-html-tabs-expand?hosting=cloud&tab=overview)

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


Tags: atl-adm

cloud

confluence-cloud

development