Adding Javascript breaks Edit page

Pieter Breugelmans December 5, 2018

On a Confluence page, I'm attempting to put in some Javascript code into an HTML macro.

<script type="text/javascript">
    document.write(AJS.Meta.get("user-display-name"));
</script>

Upon saving the page, it loads it correctly and shows my username. The problem however is when I attempt to Edit the Confluence page again. It won't let me edit the page any more. Instead of loading the page in Edit mode, it only shows my username in the browser window and it seemingly keeps loading the page.

Why would such a simple Javascript snippet cause such behavior?

Ref: based on https://community.atlassian.com/t5/Answers-Developer-Questions/Expose-the-value-of-action-remoteUser-name-to-Javascript/qaq-p/529214

1 answer

1 vote
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2018

Hello there Pieter!
I was able to replicate the behaviour you noted! I was also able to workaround it by two methods:

- Clicking the back button in the browser
- Opening the edit mode in another tab

If you are running a Confluence Server instance, you can create a user macro to achieve this:

1- Click the Cog Icon in the upper right corner
2- Search for User macros in the left hand panel
3- Select to Create a new User macro
4- Define Macro name and Macro title
5- Set Macro Body processing to Escaped
6- Insert the following in the template field:
## @noparams
$action.authenticatedUser.name
$action.authenticatedUser.fullName
7- Save the macro
8- Inser the macro in a page
9- It should display the Name and Full Name for the current user

*You can remove either FullName or name but not both.

Fur further information on this, you can check this documentation:

Class ConfluenceActionSupport


Pieter, let us know if this helps your objective!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events