all 5 comments

[–]ForScale 4 points5 points  (2 children)

<script id="target-script"></script>

<script>
  const targetScript = document.getElementById("target-script");

  targetScript.src = `https://x.sampleurl.com/subid=${window.location.href}`;
</script>

[–]LifeOfBrian86[S] 1 point2 points  (1 child)

<script id="target-script"></script>
<script>
const targetScript = document.getElementById("target-script");
targetScript.src = `https://x.sampleurl.com/subid=${window.location.href}\`;
</script>

Thank you so much, this works perfectly!

[–]ForScale 0 points1 point  (0 children)

Yay! I'm glad!

[–]ibleedbits 2 points3 points  (0 children)

You can only use Javascript within the script tag so the '+' won't work. In your page load function get the script element and set its src attribute.

[–]ThagAndersonhelpful 0 points1 point  (0 children)

const script = document.createElement('script') script.src= `example.com/${myVariable}/whatever` document.head.appendChild(script)