0

I need to capture web parameters of a URL. The URL looks like this:

http://thisisurl.com?p=parameter

I need ?p=parameter to be passed on to all HREF links on the page, so if i have:

http://thisisurl2.com">link

I should land on http://thisisurl2.com?p=parameter

Can I use JS to capture the parameter and pass it in as a variable in the HREF link?

1 Answers1

1

Example:

var url = "http://thisisurl.com?p=parameter";
var urlQueryString = url.slice(url.indexOf("?"));//return value is ?p=parameter
var hrefLink = "http://thisisurl2.com" + urlQueryString;
document.getElementById("idoflink").href = hrefLink;
<a href="" id="idoflink">Example</a>
Kevin Yan
  • 1,236
  • 11
  • 19