Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to add custom Javascript in Confluence pages?

I figured out how to add javascript calles in the header or footer but can't figure out how to add some Javascript in the pages itself.

Anybody knows?

9 answers

3 votes
Matt Ryall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 11, 2011

You could write a User Macro to do it. You need to pick a name, set the output format as "HTML" and put your JavaScript content in the body. Then you just put this macro into your pages.

If you need different JavaScript on every page, Confluence ships with a disabled HTML macro that you can enable in the "Plugins" list under the Administration. Then you can write an {html} macro with the <script> tags inside it.

Hi Thanks Matt,

But this means the Macro should be added to all the pages manually, I was more looking to add something on all pages, once for all.

Any idea?

Matt Ryall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 17, 2011

In that case, I'm not sure what your question means. If you have added JavaScript in the header or footer via Administration > Custom HTML, you should find it already on every page.

1 vote
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Jul 16, 2011

This question is very similar or at least related to:

https://answers.atlassian.com/questions/3054/javascript-inclusion

1 vote
Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 16, 2011

Roland, take a look at the web-resources Module type. If you add a plugin with one of these in there then you can have your own JS files added to all pages. Have a specific look at the contexts, such as atl.general for example

http://confluence.atlassian.com/display/CONFDEV/Web+Resource+Module#WebResourceModule-WebResourceContexts

插入宏 -html

 

<SCRIPT type="text/javascript">

var element = document.getElementById('main-content'); element.style.backgroundColor = "#33CCCC"; </SCRIPT>

0 votes
Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 03, 2014 • edited Jun 13, 2019
<web-resource key="somekey" name="some description">
   <resource type="download" name="yourfile.js"    location="/js/your file.js"/>
   <context>page</context>
</web-resource>

 

 

In your atlassian-plugin.xml , include your javascript as a web resource for page context as above.

 

I tried adding custom code in Custome HTML but the code does not appear in the pages themselves.

0 votes
Sean King
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Sep 05, 2013

If you want Javascript on an individual page use the {html} macro. Otherwise for all pages add your script in appropriate place in the the CustomHTML screen of the Admin Console.

Hi Roland,

You can try this example http://come2niks.com/?p=542 this really works.

Thanks,

Nikhil

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 11, 2013

Nikhil, this link no longer works.

i tried this but didn't work.

0 votes
jhammons
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 11, 2011

Hi Roland,

Please refer to the following document:

Be well,

Jason Hammons

Atlassian - San Francisco

That is for JIRA.  This question is about Confluence.  Therefore that link is not useful here.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events