document.addEventListener('DOMContentLoaded', function() { const redirectLinks = document.querySelectorAll('.redirectLink'); // Use class for multiple links redirectLinks.forEach(link => { link.addEventListener('click', function(event) { const href = this.getAttribute('href'); // Check if the href contains the specific domain if (href.includes('vendors.selectsoftwarereviews.com')) { // Prevent default navigation event.preventDefault(); // Encode the current page's URL const currentUrl = encodeURIComponent(window.location.href); // Construct the new URL with the current URL as a parameter const separator = href.includes('?') ? '&' : '?'; const newUrl = `${href}${separator}referrer=${currentUrl}`; console.log('Redirecting to a vendor page with referrer:', newUrl); // Redirect to the newly constructed URL window.location.href = newUrl; } else { console.log('Normal navigation to:', href); // Allow default behavior for other links } }); }); });