I have a URL that I need to redirect away from if the page visitor does not have a specific parameter in the URL when they visit the page. This is the code I have, but it seems to only work one time in Firefox and not at all when Chrome or Edge.
The goal is that if the visitor has the gcl_customer_id parameter in the URL, they stay on the page. If there is no parameter in the URL when they visit the page, they need to be redirected away instantly.
I can only do this on the client side, in browser on page load. I have no ability to handle this server side.
How can I fix this code?
<script>
function checkForXYZId() {
const urlParams = new URLSearchParams(window.location.search);
if (!urlParams.has('xyz_id')) {
window.location.href = 'https://facebook.com';
}
}
window.onload = checkForXYZId;
</script>
3
Solved it. I am using a GoHighLevel based CRM. This code was originally inserted into a hidden field. I moved the code to the Survey Footer which loads prior to the form fields. Seems to be working now!