Javascript issue while working with confluence

Hi,

I just started testing using javascript for my confluence page. This is the simple test java script im using

1
2
var element=document.getElementById("header");
element.innerHTML="New Header";

I have the following WML on my confluence page

1
2
3
{div:id=header}
Old Header
{div}

But, when i execute it, i dont get the required "New Header" as result. I get the same "Old header" text on my page. But, other commands like a simple document.write() works. It doesnt give me the required result when im trying to access a particular part of the body using divs. I dont know what i am doing wrong. Any solutions?? Plz help.... I am working on a standalone version of confluence 3.5.9.

Thanks,

Avinash

1 answer

You can add AJS.toInit(function() { to wrap your code:

<script>
  AJS.toInit(function() {
    var element=document.getElementById("header");
	element.innerHTML="New Header";
  });
</script>

Since the top navigation bar is placed inside an element with ID "header", the top navigation bar is replaced instead of the one created in your Confluence page

It works partially. I get the "new header" displayed but it doesnt replace the "old header"...it renders it at thetop left of the confluence window. How do i get it to replace the old header with the new header text?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Friday in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

280 views 11 10
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