Forums

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

Why is my custom JavaScript not working in Confluence?

SebastianK June 19, 2014

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.toInit(function(){
    AJS.$("#rte-button-publish").attr('data-tooltip','(Ctrl + S)');
});
</script>

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?

Thanks

1 answer

0 votes
Davin Studer
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.
June 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.

SebastianK June 19, 2014

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?

http://api.jquery.com/ready/

Why you no like me?

Davin Studer
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.
June 19, 2014

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

SebastianK June 19, 2014

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)

SebastianK June 19, 2014
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
TAGS
AUG Leaders

Atlassian Community Events