Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Generate A Link Based on User Input

JD April 30, 2021

Hi All,

 

I'm trying to do something I would consider relatively simple, but not having any luck. Wondering if someone can help me to create something on one of my confluence pages that takes user input, and directly navigates them to a URL based on their input. 

 

Example:

User inputs 123456 and it'll take them to page: www.abc123.com/123456

User inputs 987654 and it'll take them to page www.abc123.com/987654

 

Wondering if anyone else has successfully implemented something similar to this? I've been able to do this in HTML, but not able to use any of the HTML Macros successfully.

 

Appreciate any and all Help!

2 answers

1 vote
Thiago Masutti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 1, 2021

Hi @JD 
Welcome to the Atlassian Community.

If you are trying to add custom HTML to a Confluence page, you can use the HTML Macro.
This macro comes disabled by default so you need to work with the Confluence administrator to enable it.

Then you can insert a code similar to the below to get a text from an user.
The text is appended to a predefined URL, which is accessed clicking a button.

This code is just a sample to get you started on what you need.

<form>
<input id="thmas-input-text" type="text">
<input id="thmas-button" type="button" value="Go to link">
</form>


<script type="text/javascript">
const thmasButton = document.querySelector('#thmas-button');
const thmasInputText = document.querySelector('#thmas-input-text');

thmasButton.addEventListener('click', clickButton);

function clickButton() {
var URL = "https://www.google.com/search?q=" + thmasInputText.value;
var win = window.open(URL, "_blank");
}
</script>

custom-html-link.png

Be careful when using HTML code so you don't break any other UI resource.
Make sure to test the final code before making it available to other users. smile

Let us know if that helps.

Kind regards,
Thiago Masutti

0 votes
Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 30, 2021

Hi @JD ,

 

Here's a link similar to your needs. You can adapted it to what you need. Instead of user. replace it with the variable field you need.

 

https://community.atlassian.com/t5/Confluence-questions/Create-a-dynamic-url-link-in-Confluence-with-username-embeded/qaq-p/330063

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events