Use Case: I want to have dynamic button on a landing page that links to a different URL based on the parameters in the landing page URL.
For example: landing page link = www.testpage.com/?dc=secondtestpage.com
Desired Button Link = 'https://www.' + dc + '?etxratrackingparameters' with the outcome = "https://www.secondpagetest.com?extratrackingparameters"
I found this code to pull data from parameters:
// Parse the URL parameter
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Give the parameter a variable name
var dynamicContent = getParameterByName('dc');
This allows me to pull the dc parameter into a variable. Now I need to know how to use that variable to create URL by concatenating it to other variables or strings.
Hopefully this easy for any Javascript experts (which I am not!). Any help is appreciated.
Thanks!