function injectQueryParametersToLinks() { // Get the current query string var queryString = window.location.search; // Get all elements on the page var links = document.getElementsByTagName('a'); // Loop through each link and append the current query string to its href attribute for (var i = 0; i < links.length; i++) { var href = links[i].getAttribute('href'); // Check if href is not null or empty if (href) { // Append current query string to href links[i].setAttribute('href', href + queryString); } } } injectQueryParametersToLinks();