NEED example of a user macro that print a Javascript variable into the body

MediosPublicitarios SA March 4, 2019

I can't print in the body with "document.write()" or "innerHTML" when I'm using a variable (With out the variable works). Any idea how to do it?

2 answers

1 vote
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 19, 2019

Hello Medios,

If I understand correctly, you’re wanting to create a user macro within Confluence that has javascript within it that returns variable values as content or body of the macro itself when its placed within a Confluence page.

To understand a bit more on what you’re attempting to do exactly, could you please share the user macro you have so far that's not returning the variable? This would allow us to examine and test the macro to see if this is possible and where the issue may be.

We look forward to your response so we may help to find a solution for you.

Regards,
Stephen Sifers

Zim
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 2, 2022

Not Medios, but I have the same problem. Doing something like this:

var icebreaker = [
"Do you love working from home or would you rather be in the office? Is there a balance of both that you like best?",
"What’s the hardest part about working virtually for you? The easiest?",
"Where do you work most frequently from at home? Your office? Your kitchen table? The backyard? Your bed?",
]
var random = Math.floor(Math.random() * icebreaker.length);

I tried console.log and document.write, as well as the innerHTML trick from Matt Walsh above. I cannot get the variable (which would be icebreaker[random])

edit: With innerHTML in place, I also tried

<p id="pageIdDisplayer"></p>

When the code works, nothing displays and the page is blank.

edit2: I also tried this macro code

{html:script=^icebreak.html}
{html}

As noted here:  https://bobswift.atlassian.net/wiki/spaces/HTML/pages/6422530/Html-bobswift+macro

Which only shows the macro code without any formatting, whether or not there is an attached html file.

0 votes
Matt Walsh December 1, 2020

I did this by adding an empty div and building the innerHTML in script:

 

   ...

//Update Page Id Displayer
document.getElementById("pageIdDisplayer").innerHTML = displayStr;

});

</script>


<div style="text-align:right; font-size:x-small;" id=pageIdDisplayer></div>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events