Forums

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

Javascript issue while working with confluence

Avinash
Contributor
October 24, 2012

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

0 votes
Amalia
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.
October 24, 2012

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

Avinash
Contributor
October 25, 2012

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
TAGS
atlassian, compass learning path, get the most out of compass, internal developer platform, devex learning path, atlassian learning, transparent architecture, component catalog, improve dev experience, compass platform training

Elevate your skills and enroll in the Compass learning path today! 💻

This learning path offers short, self-paced courses to help software teams systematically manage components and services. Compass provides a unified interface for tracking distributed software architecture and team collaboration.

Learn more!
AUG Leaders

Atlassian Community Events