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
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 corner2- Search for User macros in the left hand panel3- Select to Create a new User macro4- Define Macro name and Macro title5- Set Macro Body processing to Escaped6- Insert the following in the template field:## @noparams$action.authenticatedUser.name$action.authenticatedUser.fullName7- Save the macro8- Inser the macro in a page9- 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!
It looks like you're new here. Sign in or register to get started.