I manage several websites with identical data protection policies. To streamline the process, I've created a file on a separate server that can be accessed through Ajax integration.
One crucial aspect is the ability to set an opt-out option and store the domain of each page where it's implemented.
<a href="#" id="setOptOut">Click here to opt out of tracking!</a>
<script type="text/javascript">
document.getElementById("setOptOut").addEventListener('click', function(e) {
e.preventDefault();
var redirect = 'https://' + window.location.hostname + '/privacy';
var url = encodeURIComponent(redirect);
location.href = url;
});
</script>
Although the HTML code successfully loads into the webpage via Ajax, clicking on the link does not trigger the expected function.
Interestingly, if I directly access the HTML file on the server, everything functions as intended. What could be causing this discrepancy when using Ajax?