Add this in a code module to display the parameter that is added to the url on the page.
Used for the Riga thank you coupon code.
Example: https://tstdivi.hrcws.nl/get-url-param/?code=abc
Where the parameter is ‘code’ and we need to display ‘abc’ on the page.
Option 1 (short form)
<script>
var result = new URL(location.href).searchParams.get("code");
document.write(encodeURI(result));
</script>
Code language: HTML, XML (xml)
Option 2
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const result = urlParams.get('code')
document.write(encodeURI(result));
</script>
Code language: HTML, XML (xml)
Option 3
<script>
var url_string = window.location.href
var url = new URL(url_string);
var result = url.searchParams.get("code");
document.write(encodeURI(result));
</script>
Code language: HTML, XML (xml)
Developer console
Add this if you want to see the result in the developer console:
console.log(result);
Code language: JavaScript (javascript)