Solution 1 :

I believe this will work:

  <a id="link-to-edit" href=""> Click here to execute </a>

  link = document.getElementById("link-to-edit")
  link.href = baseurl + window.location

This will use javascript to programmatically update the href to the baseurl plus current location as soon as the page/script loads. Then when you click the link will be executed properly. The key is that the href must be set at the time of clicking. In your examples, you set the href AFTER the user clicks and thus the link will not work as you intend. Hope that helps!

Problem :

I want to create a custom hyperlink which passes current URL as one of the parameter to web app endpoint (
These are the versions I tried with thought process of getting the element by Id and update the href using basic HTML properties but no luck.

Approach 1

> <script> baseurl="" 
function buildURL(item) {
>     item.href=baseurl+window.location.href;
>     return true; } 
> </head> <body> <a onclick="return buildURL(this)" href="">Google</a> </body>

Approach 2

Click on this <a href="" 
target="_self" id= "test" onclick =  buildURL() >Link  </a> to execute 
            var el_up = document.getElementById("test");
            function buildURL() {                           
                this.href = "" + document.URL; 

Any suggestions please. Is it even possible?

Update: Just to mention, I’m trying this from Azure Devops description section

enter image description here


Comment posted by JAGBIR SINGH

Thanks for the reply but with this the link itself is not clickable and I guess that’s the core problem here. Code assumes that href value will be defined at runtime (function in the script) but that never happened. Why I think so? Because even If I provide a blank href in the anchor tag ( Click here to execute ), link is clickable and pointing to current URL.

Comment posted by Sheun Aluko

HI, I edited my response to include the empty href and also added the protocol “https://” to the baseurl, as this may be required for proper link functioning. I tested this in jsbin and it is working, can you describe exactly what you mean by the “link is not clickable” ?

Comment posted by JAGBIR SINGH

What I meant by link not clickable is, hyperlink was not becoming active when href = “” wasn’t used. Though, even after this the link still points to current URL (guess that’s how markdown works). The logic written in