Why is my custom JavaScript not working in Confluence?

As a workaround for this bug: https://jira.atlassian.com/browse/CONF-33273

I'm trying to run the following JS via the "Custom HTML" at the end of HEAD:

<script type="text/javascript">
    AJS.$("#rte-button-publish").attr('data-tooltip','(Ctrl + S)');

I've run the JS via console and it works but it doesn't seem to get loaded directly on the page and I cannot figure out why since I followed this https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluenceas far as I can tell.

Any suggestions?


1 answer

0 votes
Davin Studer Community Champion Jun 19, 2014

Your JS is probably running prior to #rte-button-publish existing on the page. Which is why it works in the console, but not during page load.

I thought that might be the reason but then doesn't "AJS.toInit" take care of that problem? I thought it should but clearly it doesn't. Why not?


Why you no like me?

Davin Studer Community Champion Jun 19, 2014

If #rte-button-publish is being injected into the DOM by AJS.toInit() as well, then it might be happening after yours.

Maybe the property gets set after I've tried changing it with my hack. Not sure how I could resolve that... The injected property value depends on the OS... Does anybody know the source of the values that get injected? There seems to have been a version where the Save button tooltip is too long which messes up what I'm currently fighting...btw, when I tried to edit my answer above it didn't work at all (using Chrome)

if (!AJS.$("#rte-button-publish").length) alert("all alone");

But that would mean that the code above should create the alert, right? It does on all pages except the edit screen. This is incredibly frustrating... The bug seems to be rare and my clearly not so genius workaround doesn't cut it either.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

895 views 45 7
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