0

long time reader, first time submitter

It looks like i have the ability to insert javascript or HTML in this custom code box, but If it can be done using hTML that would be preferred.

I am trying to get the last string 'Variablex1x' which is dynamic based on the page being viewed. It is a unique identifier that corresponds to records on a different site. I would like to 'grab' that identifier and post it on the end of the target URL. When the user clicks the 'targetdomain.com' url, they are taken to the page of the targetdomain.com/Variablex1x

https://currentdomain.com/portal/x/mycase/Variablex1x

https://Targetdomain.com/Variablex1x

1 Answers1

0

You can try something like this:

$( "#target" ).click(function() {
var Variablex1x;
var newUrl;
Variablex1x = getQueryVariable(nameofvariable)
if(Variablex1x  != false){
window.location.href = newurl + "/" + Variablex1x; + "/" + Variablex1x;
}
else{
window.location.href = newurl;
}


});


function getQueryVariable(variable)
{
   var query = window.location.search.substring(1);
   var vars = query.split("&");
   for (var i=0;i<vars.length;i++) {
           var pair = vars[i].split("=");
           if(pair[0] == variable){return pair[1];}
   }
   return(false);
}

getQueryVariable comes from https://css-tricks.com/snippets/javascript/get-url-variables/ and will work as long as you know what variable you're looking for.

The idea is when you click on the link instead of actually navigating you'll fire the click function, so you'll need to update the target id. The click function will figure out if you have parameters or not, if you do it will append them to the URL and navigate, if not it will just navigate.

This is not a perfect solution but it should get you started.

IF you don't know what parameters you're looking for here is an answer of how to get those parameters: How can I get query string values in JavaScript?

Community
  • 1
  • 1
Blake
  • 641
  • 6
  • 12